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会忽略它使得3比2超过1。
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的顺序绘制z值。
- 如果两个节点共享相同的z值,则首先呈现祖先,
和兄弟姐妹以子顺序呈现。
您可以很好地解释这里呃节点树
You can find it well explained here under Understanding the Drawing Order for a Node Tree
这篇关于SpriteKit不尊重zPosition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!