在 cocos2d-x 中,如何更改精灵使用的 png?
以下作品,但它似乎有点冗长,我想知道是否有替代方法可以阻止我打电话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 );