Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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
Sprite kit xcode6模拟器中的精灵套件测试_Sprite Kit_Xcode6_Simulator_Skphysicsbody - Fatal编程技术网

Sprite kit xcode6模拟器中的精灵套件测试

Sprite kit xcode6模拟器中的精灵套件测试,sprite-kit,xcode6,simulator,skphysicsbody,Sprite Kit,Xcode6,Simulator,Skphysicsbody,我的问题是,当我想用“SKPhysicsBody”来检测我正在触摸的spritenode时,它在xcode6模拟器中返回“nil”,代码如下 初始化 触摸检测 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { /* Called when a touch begins */ for (UITouch *touch in touches) { CGPoint touchLocation = [touch lo

我的问题是,当我想用“SKPhysicsBody”来检测我正在触摸的spritenode时,它在xcode6模拟器中返回“nil”,代码如下

初始化

触摸检测

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Called when a touch begins */
for (UITouch *touch in touches) {
    CGPoint touchLocation = [touch locationInNode:self];
    NSLog(@"%f",touchLocation.x);
    SKPhysicsBody* body = [self.physicsWorld bodyAtPoint:touchLocation];
    NSLog(@"%@",body.node.name);
    if ([body.node.name isEqualToString:@"start"]){
        NSLog(@"go");
        [audioPlayer stop];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nameHide"object:@"Hide"];

        SKScene *spaceshipScene=[[SpaceshipScene alloc]initWithSize:self.size];
        SKTransition *doors=[SKTransition doorsOpenVerticalWithDuration:0.5];
        [self.view presentScene:spaceshipScene transition:doors];

    }
}
}

NSLog(@“%@”,body.node.name)返回
nil

有什么问题,请提前感谢。

尝试在节点之间循环。在最后一个Xcode 6 GM中,这与Xcode 5不同。 我也有同样的问题,我就是这样解决的。 在您的情况下,将代码更改为:

    NSArray *nodes = [self nodesAtPoint:touchLocation];
        for (SKNode *n in nodes){

 if ([n.name isEqualToString:@"start"]){
        NSLog(@"go");
        [audioPlayer stop];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nameHide"object:@"Hide"];

        SKScene *spaceshipScene=[[SpaceshipScene alloc]initWithSize:self.size];
        SKTransition *doors=[SKTransition doorsOpenVerticalWithDuration:0.5];
        [self.view presentScene:spaceshipScene transition:doors];

    }
}

我已经在我的设备(ios7.1)上进行了测试,这两种方法都可以工作,也许在ios8中只能循环通过节点?是的,我认为在ios8中必须循环以确保选择正确的节点。
    NSArray *nodes = [self nodesAtPoint:touchLocation];
        for (SKNode *n in nodes){

 if ([n.name isEqualToString:@"start"]){
        NSLog(@"go");
        [audioPlayer stop];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"nameHide"object:@"Hide"];

        SKScene *spaceshipScene=[[SpaceshipScene alloc]initWithSize:self.size];
        SKTransition *doors=[SKTransition doorsOpenVerticalWithDuration:0.5];
        [self.view presentScene:spaceshipScene transition:doors];

    }
}