gpt4 book ai didi

ios - SK 游戏中的触摸感应不感应触摸已结束

转载 作者:行者123 更新时间:2023-12-01 15:45:13 26 4
gpt4 key购买 nike

更新: 每个请求我都有 NSLogged [[event touchesForView:self.view] count]touches count 并得到 21 当故障发生时,那么事件似乎以某种方式丢失了?

这是我的两个简单方法:(已更新)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint touchLocation = [touch locationInNode:self];


if (touchLocation.x < self.size.width / 2.0f) {
NSLog(@"left");
touching = YES;
}

if (touchLocation.x > self.size.width / 2.0f) {
NSLog(@"right");
if (![rocketFlame parent]) {
[self fireRocket];
}
}
}
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches) {
NSLog([[event touchesForView:self.view] count]);
NSLog([touches count]);


CGPoint touchLocation = [touch locationInNode:self];

if (touchLocation.x < self.size.width / 2.0f) {
NSLog(@"left off");
touching = NO;
}

if (touchLocation.x > self.size.width / 2.0f) {
NSLog(@"right off");
//do nothing
}
}
}

问题是,我遇到了一个错误,即游戏无法检测到屏幕左侧的结束触摸。我不确定这个错误是否也会影响屏幕的右侧,因为该操作只运行一次并且不是连续操作,所以如果它没有感应到结束触摸我就不会注意到。

基本上,如果我同时触摸并同时结束我的触摸,它将运行 fireRocket 并将 touching 更改为 YES 但之后永远不会更改 touching 回到 NO 即使两个手指都被抬起。

这是日志输出:

right
left
2
1
right off

最佳答案

我的主要怀疑是,一旦有两次触摸,它就合并为一个事件。因此,当移除最后一个手指时,它会调用 touchesEnd 回调方法。

有几种方法可以处理您的解决方案。

第一个是在touchesEnd[[event touchesForView:self.view] count]是否返回一个大于1的数。一次它大于两个,遍历 [event touchesForView:self.view] 并确保它符合您的“右”和“左”标准。

第二个 选项是在 touchesBegan 中设置为 YES 的额外 bool 变量,但前提是您同时注册了左右。我在想类似“leftTouched”和“rightTouched”的东西。在 touchesEnd 方法中,只需查看该变量是否设置为 YES。请记住在 touchesEnd 方法的末尾添加代码以将其重置为 NO

关于ios - SK 游戏中的触摸感应不感应触摸已结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25655425/

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