gpt4 book ai didi

ios - 有没有办法在发生某些事情后停止 touches 方法?

转载 作者:行者123 更新时间:2023-11-29 03:05:29 25 4
gpt4 key购买 nike

在开发一款 IOS 游戏时,我希望在玩家碰到一 block 碎片后触摸基本上不起作用。

这是玩家碰到碎片时的代码:

-(void)dieFrom:(SKNode*)killingDebris {
_dead = YES;

[_player runAction:[SKAction sequence:@[
[SKAction repeatAction:[SKAction rotateByAngle:M_PI duration:0] count:1],
[SKAction moveByX:0 y:-700 duration:1],
[SKAction runBlock:^{
[_player removeFromParent];
}]

]]];

}

它按我想要的方式工作。问题在于播放器基于 touchesMoved 移动,因此如果用户将手指放在播放器上,它会暂时停止 moveByX 操作,使播放器在屏幕上停顿,然后删除自身,这显然看起来很糟糕。这是触摸方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesMoved:touches withEvent:event];


}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

[_player runAction:[SKAction moveTo:[[touches anyObject] locationInNode:self] duration:0.15]];

}

我尝试在 touchesMoved 方法的末尾添加以下内容:

if (_dead == YES) {
[self removeAllActions];
}

这也没有用。无论如何,当玩家撞到碎片时我可以取消任何接触吗?

最佳答案

如果您想禁用所有 View 的触摸,请执行此操作;

[self.view setUserInteractionEnabled:NO];

如果您想禁用特定 View 的触摸,请执行此操作

yourView.userInteractionEnabled = NO;

您可以通过将值设置为 YES 来启用它。

关于ios - 有没有办法在发生某些事情后停止 touches 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22827771/

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