0

我在 cocos2d 中为 iPhone 创建了两个边界框,当它们与来自 selSprite 的图像相交时,如果它们的标签匹配,则替换 targetSprite 中的图像。当边界框碰撞时,我想给出一个漂亮的动画。以下代码成功替换了精灵,但 FadeOut 动画在图像替换后运行。当图像被替换时,动画应该运行。我究竟做错了什么?任何帮助,将不胜感激。谢谢!

if (CGRectIntersectsRect(getSpriteRect, selSpriteRect)) {

        if ([selSprite tag] == ([targetSprite tag]-7)) {
            //NSLog(@"%d", [targetSprite tag]);
            //NSLog(@"%@", [selectedSpritesToBeUsedLater objectAtIndex:[selSprite tag]]);

            CCSprite *replacedImage = (CCSprite *)[self getChildByTag:[targetSprite tag]];

            CCSprite *spriteToBeUsedInTex = [selectedSpritesToBeUsedLater objectAtIndex:[selSprite tag]];

            id removeSpriteAction = [CCFadeOut actionWithDuration:2.0f];

            id removeSelSprite = [CCCallFunc actionWithTarget:self selector:@selector(removeSelSpriteByTag)];

            CCSequence *sequence = [CCSequence actions:removeSpriteAction, removeSelSprite, nil];

            [selSprite runAction:sequence]; 

            CCTexture2D *tex = [[CCTextureCache sharedTextureCache] addImage:[NSString stringWithFormat:@"color-0%d.png", [spriteToBeUsedInTex tag]+1]];

            [replacedImage setTexture:tex];

        }
    }
} }

-(void)removeSelSpriteByTag {
[self removeChildByTag:[selSprite tag] cleanup:YES]; }
4

1 回答 1

1

你应该使用CCSpawn而不是CCSequencethen。

于 2012-07-24T23:40:17.193 回答