gpt4 book ai didi

ios - SKScene:场景的界限

转载 作者:行者123 更新时间:2023-12-01 18:11:30 30 4
gpt4 key购买 nike

我如何获得场景的边界?

我正在测试演示,并以这种方式初始化场景:

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)不对应!!

最佳答案

您需要将GameScene的大小设置为等于其SKView的大小。您可以在didMoveToViewGameScene中执行此操作:

-(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];

关于ios - SKScene:场景的界限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30422119/

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