SpriteKit 不尊重 zPosition? [英] SpriteKit not respecting zPosition?

查看:18
本文介绍了SpriteKit 不尊重 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:

  1. 父级在渲染其子级之前绘制其内容.
  2. 子项按照它们在子项中出现的顺序呈现数组.

当您考虑 z 位置时,节点树的呈现方式如下:

When you take z positions into account, here is how the node tree is rendered:

  1. 计算每个节点的全局 z 位置.
  2. 节点按 z 值从小到大的顺序绘制.
  3. 如果两个节点共享相同的 z 值,则先渲染祖先,并且兄弟姐妹按子顺序呈现.

您可以在这里找到很好的解释/a> 在了解节点树的绘制顺序下

You can find it well explained here under Understanding the Drawing Order for a Node Tree

这篇关于SpriteKit 不尊重 zPosition?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆