SKScene:场景的界限

时间:2015-05-24 09:47:40

标签: ios objective-c iphone sprite-kit game-engine

我如何获得场景的界限?

我正在使用demo进行测试,并以这种方式初始化场景:

GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];
scene.scaleMode = SKSceneScaleModeAspectFill;

所以,当我点击屏幕时,我会记录:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:   self];
        NSLog(@"%f, %f", location.x, location.y);
    }
}

当我按下左下角时我大约300-0而我期待0-0。

如何获得左下角的左上角?我找不到像这样的方法:

[scene getBounds]

Scene.frame打印:(0,0,1024,768)不对应!!

2 个答案:

答案 0 :(得分:4)

您需要将GameScene的大小设置为等于SKView的大小。您可以在didMoveToView的{​​{1}}中执行此操作:

GameScene

或者,您可以在实例化-(void)didMoveToView:(SKView *)view { [super didMoveToView: view]; self.size = view.bounds.size; }

时设置大小
GameScene

答案 1 :(得分:0)

像这样初始化场景:

 GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
 scene.scaleMode = SKSceneScaleModeAspectFill;

测试这样的坐标:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];

    /* Pressed node */
    SKNode *node = [self nodeAtPoint:location];

    NSLog(@"x - %f; y - %f", location.x, location.y);
}