0

在此动画中:

    - (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    self.isTouchEnabled = NO;
    if (scoreLabel.opacity == 225) {
        NSLog(@"fadeOut");
        CCSequence *fadeOut = [CCSequence actions:[CCFadeOut actionWithDuration:0.5], [CCCallFuncN actionWithTarget:self 
        selector:@selector(enableTouches)], nil];
        [scoreLabel runAction:fadeOut];
        [livesLabel runAction:[[fadeOut copy] autorelease]];
    }
    else {
        NSLog(@"fadeIn");
        CCSequence *fadeIn = [CCSequence actions:[CCFadeIn actionWithDuration:0.5], [CCCallFuncN actionWithTarget:self 
        selector:@selector(enableTouches)], nil];
        [scoreLabel runAction:fadeIn];
        [livesLabel runAction:[[fadeIn copy] autorelease]];
         }
}

我试图简单地淡出/淡入标签。但问题是,我想确保在标签动画时不会调用此方法。

如果您查看代码,我会尝试通过调用此方法来做到这一点:

    - (void)enableTouches {
    NSLog(@"ET");
        self.isTouchEnabled = YES;
}

但这似乎不起作用。如果我在标签动画时触摸屏幕,它会在中途弄乱动画并且不会做我想要的。

有任何想法吗?

谢谢!

4

2 回答 2

2

如果有人遇到同样的问题,我最终会这样做:

- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    self.isTouchEnabled = NO;

    if(label1.opacity == 0 )
    {
        CCFadeIn* fadeIn = [CCFadeIn actionWithDuration:0.5];
        CCCallBlock* fadeCompleted = [CCCallBlock actionWithBlock:^{ self.isTouchEnabled = YES; }];     

        [label1 runAction:[CCSequence actions:fadeIn, fadeCompleted, nil]];
        [label2 runAction:[[fadeIn copy] autorelease]];
    }
    else
    {
        CCFadeOut* fadeOut = [CCFadeOut actionWithDuration:0.5];
        CCCallBlock* fadeCompleted = [CCCallBlock actionWithBlock:^{ self.isTouchEnabled = YES; }];     

        [label1 runAction:[CCSequence actions:fadeOut, fadeCompleted, nil]];
        [label2 runAction:[[fadeOut copy] autorelease]];
    }
}
于 2011-11-19T01:23:27.040 回答
1

In case you didn't know, you can assign tags to actions the same way you can assign tags to nodes. Then you can call getActionByTag: on the object that is running the action to either get nil or a pointer to the action. By checking if the return value is nil or an action you will know if the certain action/animation you are looking for is playing. That way you might be able to do this without additional variables.

于 2011-11-19T12:51:40.647 回答