【问题标题】:Change CCSprite images at runtime在运行时更改 CCSprite 图像
【发布时间】:2012-01-20 07:41:06
【问题描述】:

需要在运行时更改CCSprite 图像,我必须删除以前加载的图像并在NSTimer 的特定中间后显示新图像,我正在使用[imagesContainer removeChildByTag:0 cleanup:YES]; 但无法正常工作

任何帮助将不胜感激

【问题讨论】:

  • 我在一个类似问题中看到以下标记为答案,但它无法实现这个 CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"new_image_name"]; [spriteWant2Change setTexture: tex]; \

标签: iphone cocos2d-iphone


【解决方案1】:

您可以像现在一样删除精灵并添加一个新精灵,但请记住使用 addChild 将其添加到图层:

 CCSprite *theNewSprite = [CCSprite spriteWithFile:@"newImage.png"];
 [LayerYouWantToAdd addChild:theNewSprite]

或者只是改变精灵的纹理。这对我有用。

[theSprite setTexture:[[CCSprite spriteWithFile:@"newImage.png"]texture]];

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多