Changing the image of a CCSprite

后端 未结 11 1793
离开以前
离开以前 2020-12-24 12:12

I have created a number of CCSprites using spriteWithFile.

How do I change the image for the sprite during runtime?

I need to change a few sprites images qui

11条回答
  •  醉梦人生
    2020-12-24 12:32

    If you are using SpriteSheets, this will work.

    NSString* newSprite = [NSString stringWithString:@"SPRITE_NAME.png"];
    CCSpriteFrameCache* cache = [CCSpriteFrameCache sharedSpriteFrameCache];
    [sprite setDisplayFrame:[cache spriteFrameByName:newSprite]];
    

提交回复
热议问题