私のプログラムでは、iOS Sim で画面をタップすると、CCMoveTo を使用してカードが配られます。アニメーションが完了するまでに 0.4 秒かかります。画面をもう一度タップすると、次のカード セットが配られます。この 2 番目のアニメーションにも 0.4 秒かかります。私がやりたいことは、最初のアニメーションが完了する前に、プログラムがその 2 番目のセットのカードを配ることを禁止することだけです。sleep() を試してみましたが、明らかに、目的の効果を達成できませんでした。また、Cocos2D の CCDelayTime をいくつかの異なる方法で試してみましたが、望ましい結果が得られませんでした。これを行うための最も簡単でメモリ効率の良い方法は何ですか?
編集: @crackity_jones - これが私の HelloWorldLayer ファイルと、移動を許可する CCSprite 用に作成したカテゴリです。
HelloWorldLayer.h
#import <GameKit/GameKit.h>
#import "CCSprite+MoveActions.h"
#import "cocos2d.h"
// globals
CCSprite *card1;
...
CCSprite *card9;
@interface HelloWorldLayer : CCLayer {
NSMutableArray *deck;
...
int touchCount;
}
...
@end
HelloWorldLayer.m
...
-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchCount++;
[self nextRound];
}
// one method to handle all rounds dealt
-(void)nextRound {
if (touchCount == 1) {
[self removeAllCards];
[deck shuffle];
[self dealFirstRound];
} else if (touchCount == 2) {
[self dealSecondRound];
} else if (touchCount == 3) {
[self dealThirdRound];
} else if (touchCount == 4) {
[self dealFourthRound];
touchCount = 0;
}
}
-(NSMutableArray *)makeDeck {
// create mutable array of 52 card sprites
}
-(void)dealFirstRound {
...
// declare, define, add card objects to layer at start-point here
…
// the "moveToPositionX" methods contain the animation code
[firstCard moveToPosition1];
[secondCard …2];
[third...3];
[fourth...4];
}
// Also methods for removing all rounds of cards
…
@end
CCSprite (MoveActions)
#import "CCSprite+MoveActions.h"
#define kCardTravelTime .1
@implementation CCSprite (MoveActions)
-(void)moveToPosition1 {
CGSize size = [[CCDirector sharedDirector] winSize];
[self runAction:[CCMoveTo actionWithDuration:kCardTravelTime
position:CGPointMake(size.width/2 - card1.contentSize.width/4, card1.contentSize.height/2 + holeCard1.contentSize.height/5)]];
CCDelayTime *waitTime = [CCDelayTime actionWithDuration:.4];
[self runAction:waitTime];
}
-(void)moveToPosition2 {
CGSize size = [[CCDirector sharedDirector] winSize];
CCDelayTime *delay = [CCDelayTime actionWithDuration:.2];
CCMoveTo *move = [CCMoveTo actionWithDuration:kCardTravelTime
position:CGPointMake(size.width/2 + card1.contentSize.width/4, card1.contentSize.height/2 + holeCard1.contentSize.height/5)];
[self runAction:[CCSequence actions:delay, move, nil]];
}
// rest of the methods 3-9 look like the above, essentially
@end