所有
我面临一个问题,问题是我想要无限时间点击一个对象,它只向我展示一次动画..我怎么能这样做..请给我一个这个想法
代码
ccTouches功能
if(firstValue >= 125 && sencndvalu <=138)
{
if(multipleTouch == 0)
{
[self FaceAni:@"chammat.plist"];
}
multipleTouch ++;
if(multipleTouch > 2)
[self fallingAnimation:@"fallingNew.plist"];
}
}
- (void)FaceAni:(NSString *)plistFile {
multipleTouch = 0;
animationIsOn = 1;
[self removebackgroundTexture];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:plistFile];
NSString *changeFileName = [NSString stringWithFormat:@"%@", plistFile];
changeFileName = [changeFileName stringByReplacingOccurrencesOfString:@".plist" withString:@".png"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:changeFileName];
[self addChild:spriteSheet];
// Load up the frames of our animation
walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 20; ++i)
{
if(i <= 9)
{
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Chmaat_0000%d.png", i]]];
}
else
{
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Chmaat_000%d.png", i]]];
}
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.10f];
// Create a sprite for our bear
CGSize winSize = [CCDirector sharedDirector].winSize;
self.bear = [CCSprite spriteWithSpriteFrameName:@"Chmaat_00000.png"];
_bear.position = ccp(winSize.width/2, 230);
self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
//[_bear runAction:_walkAction];
[spriteSheet addChild:_bear];
[_bear runAction:_walkAction];
// [[SimpleAudioEngine sharedEngine] playEffect:@“slap3.wav”];
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(removeFrame) userInfo:nil repeats:NO];
}
答案 0 :(得分:0)
你可以:
第一次显示动画时,标志将设置为NO,动画将不再运行。
答案 1 :(得分:0)
从我对你的问题的理解。使用线程方法来运行动画并检查线程,如果线程不工作则做动画。 代码将是这样的,
- (void)waitForSoundDriverThreadToFinish {
while (soundPlayerThread && ![soundPlayerThread isFinished]) { // Wait for the thread to finish.
[NSThread sleepForTimeInterval:0.1];
}
}
- (void)startDriverThread {
if (soundPlayerThread != nil) {
[soundPlayerThread cancel];
[self waitForSoundDriverThreadToFinish];
}
NSThread *driverThread = [[NSThread alloc] initWithTarget:self selector:@selector(startDriverTimer:) object:nil];
self.soundPlayerThread = driverThread;
[driverThread release];
[self.soundPlayerThread start];
}
- (void)stopDriverThread {
[self.soundPlayerThread cancel];
[self waitForSoundDriverThreadToFinish];
self.soundPlayerThread = nil;
}
此代码来自Metronome示例代码