我正在尽最大努力利用我的“响应式”/“自适应”知识将其应用于我的 SKScene
中的定位。
但是,似乎有问题。由于场景的宽度/高度不准确。
在此示例中, View 的 anchor 是中心点,即 0.5、0.5。
SKLabelNode *label = [SKLabelNode labelNodeWithText:@"Welcome to the table..."];
label.position = CGPointMake(0,0);
label.alpha = 0;
[self addChild:label];
现在让我们说,我想把它移到屏幕底部。我使用屏幕大小调整逻辑,因此我可以将其应用于每台设备。
label.position = CGPointMake(0, self.view.frame.height/2 + label.frame.height);
据我所知,它应该将 X 与 anchor 对齐,然后从 anchor 减去 y。所以 CenterPoint - 半屏幕高度 + 标签高度.. 然而,事实并非如此。它在屏幕外某处无法正常工作。
我也尝试过使用 self.frame.size.height
& self.view.bounds.size.height
最佳答案
听起来您的 SKScene
的大小与其 SKView
的大小不匹配。尝试将场景的 scaleMode
设置为 ResizeFill
。来自 SKScene
documentation on ResizeFill
:
The scene is not scaled to match the view. Instead, the scene is automatically resized so that its dimensions always match those of the view.
关于ios - SKScene 边界和定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30890395/