Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 精灵套件游戏没有检测到两个同时触碰_Ios_Xcode_Sprite Kit - Fatal编程技术网

Ios 精灵套件游戏没有检测到两个同时触碰

Ios 精灵套件游戏没有检测到两个同时触碰,ios,xcode,sprite-kit,Ios,Xcode,Sprite Kit,我正在开发一款精灵套件游戏,需要对屏幕左侧或右侧的触摸做出反应。我在另一个问题中找到了这个解决方案: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint touchLocation = [touch locationInNode:self]; if (touchLocation.x < self.size.width

我正在开发一款精灵套件游戏,需要对屏幕左侧或右侧的触摸做出反应。我在另一个问题中找到了这个解决方案:

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

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

if (touchLocation.x > self.size.width / 2.0f) {
    [self drawRocket];
}
}

以及

-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置Innode:self];
用于(UITouch*触摸屏){
如果(触摸位置.xself.size.width/2.0f){
如果(![rocketFlame父级]){
[自燃火箭];
}
}
}
}


我仍然有同样的问题。

在初始化方法中添加以下行 self.view.multipleTouchEnabled=是

for (UITouch *touch in touches) {

CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
    touching = YES;
}

if (touchLocation.x > self.size.width / 2.0f) {
    [self drawRocket];
}
}
用于(UITouch*触摸屏){
CGPoint touchLocation=[触摸位置Innode:self];
如果(触摸位置.xself.size.width/2.0f){
[自拔火箭];
}
}

使用鼠标和键盘模拟多点触控手势

您正在定义一个局部变量,该变量隐藏用于在触控事件上循环的变量。请参阅下面代码中的注释

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {

        // The following statement is causing the issue. Delete it.
        //UITouch *touch = [touches anyObject];

        CGPoint touchLocation = [touch locationInNode:self];

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

        if (touchLocation.x > self.size.width / 2.0f) {
            if (![rocketFlame parent]) {
                [self fireRocket];
            }
        }
    }
}
-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)event{
用于(UITouch*触摸屏){
//以下语句导致问题。请删除它。
//UITouch*touch=[触摸任何对象];
CGPoint touchLocation=[触摸位置Innode:self];
如果(触摸位置.xself.size.width/2.0f){
如果(![rocketFlame父级]){
[自燃火箭];
}
}
}
}

您需要处理所有触摸,而不仅仅是[触摸任何对象]。。ie在每次触摸上枚举:对于(UITouch*touch in Touchs){..}@LearnCos2D请用代码示例回答,我不确定要更改哪一行。我尝试了此操作,但仍然存在相同的问题。请在循环中尝试触摸位置查看我的编辑,我在两个位置尝试了此操作,但都不起作用。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];


for (UITouch *touch in touches) {
    if (touchLocation.x < self.size.width / 2.0f) {
        touching = YES;
    }

    if (touchLocation.x > self.size.width / 2.0f) {
        if (![rocketFlame parent]) {
            [self fireRocket];
        }
    }
}
for (UITouch *touch in touches) {

CGPoint touchLocation = [touch locationInNode:self];
if (touchLocation.x < self.size.width / 2.0f) {
    touching = YES;
}

if (touchLocation.x > self.size.width / 2.0f) {
    [self drawRocket];
}
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {

        // The following statement is causing the issue. Delete it.
        //UITouch *touch = [touches anyObject];

        CGPoint touchLocation = [touch locationInNode:self];

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

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