2015-05-24 59 views
1

如何獲取場景的邊界?SKScene:場景的邊界

我與演示測試,我以這種方式初始化一幕:

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)不相應!

回答

4

您需要將GameScene的大小設置爲等於其SKView的大小。您可以在您的GameScenedidMoveToView做到這一點:

-(void)didMoveToView:(SKView *)view { 
    [super didMoveToView: view]; 
    self.size = view.bounds.size; 
} 

或者,當你實例化GameScene您可以設置大小:

SKView * skView = (SKView *)self.view; 
// ... 

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

[skView presentScene:scene]; 
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); 
}