Changing the image of a CCSprite

后端 未结 11 1911
离开以前
离开以前 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:45

    if you want to change the images continuously then write following code in your init method

    CCTexture2D *tex1 = [[CCTextureCache sharedTextureCache] addImage:@"image1.png"]; CCTexture2D *tex2 = [[CCTextureCache sharedTextureCache] addImage:@"image2.png"]; CCTexture2D *tex3 = [[CCTextureCache sharedTextureCache] addImage:@"image3.png"]; CCSprite *sprite = [CCSprite spriteWithTexture:tex1]; //Make above variables as class level to access in whole class [self addChild:sprite]; //position the sprite according to your need

    write this line where you want to change the image

    [sprite setTexture:tex3];

提交回复
热议问题