In cocos2d-x, how can I change the png used by the sprite?
The following steps, however, seem a bit long, and I was wondering if there is an alternative that prevents me from calling new ?
// create sprite with original png m_pSpr = CCSprite::create( "1.png" ); m_pSpr->setPosition( ccp( 100, 100 ) ); this->addChild( m_pSpr ); // now change the png that is used by the sprite // new image from png file CCImage* img = new CCImage(); img->initWithImageFile( "2.png", CCImage::kFmtPng ); // new texture from image CCTexture2D* tex = new CCTexture2D(); tex->initWithImage( img ); // finally change texture of sprite m_pSpr->setTexture( tex );
source share