在多个触摸上运行单个动画

时间:2011-09-21 11:28:36

标签: iphone xcode

所有

我面临一个问题,问题是我想要无限时间点击一个对象,它只向我展示一次动画..我怎么能这样做..请给我一个这个想法

代码

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];

}

2 个答案:

答案 0 :(得分:0)

你可以:

  • 设置一个以YES
  • 值启动的布尔标志
  • 在运行动画的方法中,检查该布尔标志的状态。如果是,则运行动画
  • 然后让该方法将标志设置为NO。

第一次显示动画时,标志将设置为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示例代码