ios - SKScene 边界和定位

标签 ios sprite-kit positioning skscene

我正在尽最大努力利用我的“响应式”/“自适应”知识将其应用于我的 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/

相关文章:

ios - 如何在 Swift 3 的子类中覆盖 Init()

ios - 在 Xcode 中,如何为每个目标 iOS 应用程序使用不同的 AppIcon?

ios - 通过 Braintree 商家帐户付款

reference - iOS7创建和使用SKTextureAtlas的正确方法是什么?

css - 如何在不进行手动高度/边距计算的情况下将两个元素右对齐?

html - 相对于直接亲属的绝对 DIV position().left?

ios - 如何在 UISearchBar 上方显示内容?

memory - 遇到 iPad Mini 内存问题

swift - 播放声音文件时启动时出现白屏 SKAction

html - HTML 元素的定位