我目前正在开发一款只有几个屏幕的游戏。我在场景中添加了一些 Sprite 纹理,如下所示。
为什么我的图像在模拟器中加载不一致?
仪表板场景文件
仪表板模拟器尝试 1
这是在 iOS 模拟器中加载应用程序的一次尝试。正如您所看到的,在此实例中,没有从上面的 spritekit 场景文件中加载许多图像。
仪表板模拟器尝试 2
下面是在模拟器中加载仪表板场景的另一种尝试。结果 View 截然不同,但没有更改任何代码。我不明白渲染的图像怎么会有这样的变化。
最佳答案
来自苹果
The default value is 0.0. The positive z axis is projected toward the viewer so that nodes with larger z-position values are closer to the viewer. When a node tree is rendered, the height of each node (in absolute coordinates) is calculated and then all nodes in the tree are rendered from smallest z-position value to largest z-position value. If multiple nodes share the same z-position, those nodes are sorted so that parent nodes are drawn before their children, and siblings are rendered in the order that they appear in their parent’s children array. Hit-testing is processed in the opposite order.
The SKView class’s ignoresSiblingOrder property controls whether node sorting is enabled for nodes at the same z-position.
基本上,通过将它们全部设置为 0,您可以随机选择它们按照您希望的顺序进行布局。您可以尝试设置 ignoresSiblingOrder
来查看是否确实将它们以正确的顺序放置在代码中,并查看它们是否会以正确的顺序出现。
但我强烈建议您将它们放置在结构化层 z 顺序中,而不是这样做。
即。
background.zPosition = 0
hero.zPosition = 1
scoreLabel.zPosition = 500
再次来自 Apple 关于 ignoresSiblingOrder
The default value is false, which means that when multiple nodes share the same z position, those nodes are sorted and rendered in a deterministic order. Parents are rendered before their children, and siblings are rendered in array order. When this property is set to true, the position of the nodes in the tree is ignored when determining the rendering order. The rendering order of nodes at the same z position is arbitrary and may change every time a new frame is rendered. When sibling and parent order is ignored, SpriteKit applies additional optimizations to improve rendering performance. If you need nodes to be rendered in a specific and deterministic order, you must set the z position of those nodes.
关于ios - 为什么我的图像有时无法在模拟器中显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49613116/