作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在开发一款 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/
我是一名优秀的程序员,十分优秀!