Copying a Sprite Image to another Sprite in Cocos2D

By | March 11, 2011

Hi,

Suppose you want to copy a sprite image to another new sprite while using cocos2D. What you do?
See the following code…

Let oldSprite be your first sprite

CCSprite *oldSprite = [CCSprite spriteWithFile:@"ImgOne.png"];

And newSprite be your second sprite

CCSprite *newSprite  = [CCSprite spriteWithTexture:[oldSprite texture]];

That’s it! Done! Now newSprite too contain ImgOne as Sprite.

🙂

Leave a Reply

Your email address will not be published. Required fields are marked *