我正在寫一個使用cocos2D的二十一點遊戲。 我使用CCSequence很多,並在我的代碼中的許多地方有問題。 我遇到的問題是一個動作在前一個動作完成之前發射。 例如:CCS序列不等待動作完成,然後開始下一個動作
-(void)standButtonPressed:(id)sender
{
[self removeChildByTag:333];
if ((splitNumber<3)&&(numberSplitHits>0))
{
[self removeChildByTag:333];
splitNumber++;
if ([[hands objectAtIndex:splitNumber]handTotal]==0)
goto end;
[self afterSpliting];
[self addArrow];
return;
}
end:
[self removeChildByTag:333];
[[BackgroundLayer sharedBackground]menuSetup:hand gamePhase:3];
BJDrawnCard *holeCard = [dealerHand getFlippedCard];
[holeCard flipCard];
[[SimpleAudioEngine sharedEngine] playEffect:SND_DEAL_CARD];
[self generateDealerHandDisplay];
[self updateDealerHandScoreDisplay];
id myCallFun1 = [CCCallFunc actionWithTarget:self selector:@selector(finishDrawingDealer)];
id myCallFun2 = [CCCallFunc actionWithTarget:self selector:@selector(checkWhoWonHand)];
id myCallFun3 = [CCCallFuncND actionWithTarget:[BackgroundLayer sharedBackground] selector:@selector(menuSetup:gamePhase:)data:(void*)6];
CCDelayTime *delay = [CCDelayTime actionWithDuration:2];
[self runAction:[CCSequence actions:myCallFun1,delay,myCallFun2,myCallFun3 ,nil]];
}
所以myCallFunc2將開始運行myCallFun1完成之前。 當我使用CCSequence時,在我的代碼的其他部分中遇到同樣的問題,操作將按順序啓動,但不會等待某個操作在下一個啓動之前完成。
有沒有更好的方法來排序動作,或者甚至可以替代CCSequence?
這裏是myCallFun1調用方法:
-(void)finishDrawingDealer
{
if (dealerHand.handTotal<17)
{
drawnCard=[havila drawFromDeck];
[drawnCard setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:drawnCard.imageFileName]];
CCMoveTo *move =[self animateDealerCards:drawnCard andPosition:[self dealerCardPosition]];
CCDelayTime *delay = [CCDelayTime
actionWithDuration:0.5];
[dealerHand getCard:drawnCard];
//Run the action
numDealerHits++;
[self performSelector:@selector(updateDealerHandScoreDisplay) withObject:nil afterDelay:1.0];
if (dealerHand.handTotal<17) {
id more = [CCCallFunc actionWithTarget:self selector:@selector(finishDrawingDealer)];
[drawnCard runAction:[CCSequence actions:delay,move,delay,more,nil]];
} else {
[drawnCard runAction:[CCSequence actions:delay,move,delay,nil]];
}
if (dealerHand.handTotal>21)
[self dealerBusted];
}
}
你應該檢查你的縮進代碼的方式。 –
您如何注意myClassFun2在myClassFun1完成之前調用?我想你會記錄它或使用調試器。也請張貼代碼或任何使你得出這個結論的東西。 –
myClassFun1的功能是什麼?你可以發佈實施嗎? – giorashc