ios - Sprite Kit 只允许一次触摸

标签 ios iphone objective-c ios7 sprite-kit

我一直在寻找类似的问题,但没有找到,所以如果有人问过这个问题,我深表歉意,但我在限制 SKScene 允许我拥有的触摸数量方面遇到了问题。我已经实现了 touchesBegan:withEvent: 方法,并为动画设置了我的 SKAction(s),但我想要的是在 Sprite 节点动画时,我不希望它有接受另一个触摸的能力.

我试图计算正在发生的触摸次数,但无论如何都不起作用,所以我正处于停止点。

因此,我的基本问题是:如何在我的场景中创建“一次触摸,然后等待动画结束,然后再进行另一次触摸”?

代码如下:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */

SKAction *jump = [SKAction moveToY:400 duration:.4];
SKAction *down = [SKAction moveToY:CGRectGetMidY(self.frame) duration:.4];
SKAction *action = [SKAction sequence:@[jump, down]];

for (UITouch *touch in touches) {
    NSInteger touchesMax = 1;
    NSInteger actualTouches = [touches count];
    NSLog(@"%ld", (long)actualTouches);

    actualTouches++;

    if (actualTouches > touchesMax) {
        [farmer removeAllActions];
    }
    else {
        [farmer runAction:action];
    }
}
}

感谢任何帮助

最佳答案

我相信这会奏效。在 touchesBegan 开始

self.userInteractionEnabled = NO;

然后定义一个新的SKAction来启用用户交互:

SKAction *enable = [SKAction runBlock:^{ self.userInteractionEnabled = YES; }];

将其添加到您的序列中:

SKAction *action = [SKAction sequence:@[jump, down, enable]];

关于ios - Sprite Kit 只允许一次触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21629546/

相关文章:

iphone - ARC 下紧密循环中 UIKit 的内存管理

iphone - 向应用程序添加背景音乐时构建失败

iOS 一些 UIImageView 被拉伸(stretch)

ios - UINavigationController 使用 SWRevealViewController 阻止 UITabBar

objective-c - 如何获取用户当前的UITextField的属性名称作为字符串?

ios - SpriteKit : SKNode zRotation + Anti-Aliasing

ios - 向 MKMapview 添加自定义注释

iphone - 如何知道 Pubnub 中的退订 channel 请求是否成功?

iphone - 如果日期的年份已经过去,则将日期的年份增加一

iphone - xcode swift - 将文本格式化为电话号码