0
我已經在iPhone的cocos2d中創建了兩個邊界框,當它們與selSprite中的圖像相交時,如果它們的標記匹配,則替換targetSprite中的圖像。我想在邊界框碰撞時給出一個很好的動畫。以下代碼成功替換了精靈,但FadeOut動畫運行AFTER圖像已被替換。當圖像被替換時,動畫應該運行。我究竟做錯了什麼?任何幫助,將不勝感激。謝謝!用動畫替換cocos2d中的Sprite
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]; }
我不工作。你能指導我如何做到這一點?我用CCSpawn替換了CCSequence。現在沒有效果,它只是卡入到位! – 2012-07-25 04:54:27