gpt4 book ai didi

ios - 在动画期间防止 Cocos2D 触摸?

转载 作者:行者123 更新时间:2023-11-28 20:41:53 24 4
gpt4 key购买 nike

在此动画中:

    - (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;
}

但是好像不行。如果我在标签动画时触摸屏幕,它会在中途弄乱动画并且不会执行我想要的操作。

有什么想法吗?

谢谢!

最佳答案

我最后这样做是为了防止有人遇到同样的问题:

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

关于ios - 在动画期间防止 Cocos2D 触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8190808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com