iphone - 连续切换 Sprite 图像(不显示动画)

标签 iphone ios xcode cocos2d-iphone

使用下面的代码,我可以连续改变我的 CCSprite 的颜色,但是我需要用这段代码改变我的 CCSprite 图像。我该怎么做?

注意:不想只显示帧变化的动画,我需要在我的代码中选择一个不断变化的 Sprite 。

 id delayTime1 = [CCDelayTime actionWithDuration:0.05f];
    id calFun1   = [CCCallBlock actionWithBlock:^{
        //HERE SET BLUE TEXTURE..
       // m_spriteBubbleWeapon= [CCSprite spriteWithFile:[NSString stringWithFormat:@"firstimage.png"]];// //kill when i uncomment it 

        m_spriteBubbleWeapon.color = ccc3(255,0,255); // works current

    }];
    id delayTime2 = [CCDelayTime actionWithDuration:0.05f];
    id calFun2   = [CCCallBlock actionWithBlock:^{
        //HERE SET RED TEXTURE..
        //m_spriteBubbleWeapon= [CCSprite spriteWithFile:[NSString stringWithFormat:@"second image.png"]];//kill when i uncomment it

        m_spriteBubbleWeapon.color = ccc3(255,0,0);//work correct

    }];

    id sequece = [CCSequence actions:delayTime1, calFun1, delayTime2, calFun2, nil];
    id repeate = [CCRepeatForever actionWithAction:sequece];

    [sprite runAction:repeate];

最佳答案

在类的前面定义一个属性 tex1 和 tex2(例如在 init 中):

CCTexture2D* tex1 = [[CCTextureCache sharedTextureCache] addImage:@"firstimage.png"];
CCTexture2D* tex2 = [[CCTextureCache sharedTextureCache] addImage:@"secondimage.png"];

然后在您的代码中为现有 Sprite 交换纹理:

id delayTime1 = [CCDelayTime actionWithDuration:0.05f];
id calFun1   = [CCCallBlock actionWithBlock:^{
    //HERE SET BLUE TEXTURE..
    [m_spriteBubbleWeapon setTexture:tex1];
    m_spriteBubbleWeapon.color = ccc3(255,0,255); // works current
}];

...

    //HERE SET RED TEXTURE..
    [m_spriteBubblWeapon setTexture:tex2];

关于iphone - 连续切换 Sprite 图像(不显示动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15879767/

相关文章:

ios - iPhone SDK : Open Default Message tones list

ios - CallKit 可以在交换通话后重新激活声音

ios - 是否可以通过 xcode 更改 iOS 应用程序的名称?

c++ - 如何使用 XCode 6.1 C++ Debug模式检查所有局部变量

ios - 如何检测 UIScrollView 何时完成滚动

ios - 我如何在使用我的应用程序时关闭其他应用程序的推送通知

iphone - UISearchBar 表部分索引标题重叠

ios - 在 iphone 上同时进行调试和发布构建

ios - 如何转发声明 CoreFoundation 类型?

c - 为什么 Xcode 无法在我的 Macbook Pro 上运行?