SpriteKit 不尊重 zPosition? [英] SpriteKit not respecting zPosition?
问题描述
addChild 和 zPosition 对场景有什么真正的影响?
What effect addChild and zPosition really have on a scene?
我的意思是:假设我这样做
I mean this: suppose I do this
sprite1.zPosition = 50;
sprite2.zPosition = 10;
sprite3.zPosition = 30;
稍后再做
[self addChild:sprite1];
[self addChild:sprite2];
[self addChild:sprite3];
根据 SpriteKit 并考虑 zPosition 顺序,sprite1 应该在 sprite2 上渲染在 sprite3 上,但 spriteKit 忽略了这一点,并在 1 上渲染 3 over 2.
according to SpriteKit and considering zPosition order, sprite1 should be rendered over sprite3 over sprite2 but spriteKit ignores that and renders 3 over 2 over 1.
我错过了什么吗?
推荐答案
如果他们有相同的父级,那将是正确的.如果他们可以不同的父母,父母的z顺序也被考虑在内.
If they have the same parent that would be true. In case they can different parents, the z order of parents is also taken into account.
场景渲染的标准行为遵循一对简单的规则:
The standard behavior for scene rendering follows a simple pair of rules:
- 父级在渲染其子级之前绘制其内容.
- 子项按照它们在子项中出现的顺序呈现数组.
当您考虑 z 位置时,节点树的呈现方式如下:
When you take z positions into account, here is how the node tree is rendered:
- 计算每个节点的全局 z 位置.
- 节点按 z 值从小到大的顺序绘制.
- 如果两个节点共享相同的 z 值,则先渲染祖先,并且兄弟姐妹按子顺序呈现.
You can find it well explained here under Understanding the Drawing Order for a Node Tree
这篇关于SpriteKit 不尊重 zPosition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!