[英]How to programmatically add child with zPosition to scene created with Scene Editor
I'm having trouble controlling the zPosition of a node. 我在控制节点的zPosition时遇到问题。 If created on the scene editor I have no problem, but later when I want to add a new node with code, the zPosition is not respected.
如果在场景编辑器上创建我没有问题,但是稍后当我想添加带有代码的新节点时,就不会考虑zPosition。
//GameScene
override func didMove(to view: SKView) {
super.didMove(to: view)
let circle = SKShapeNode(circleOfRadius: 10)
circle.zPosition = -1
self.addChild(circle)
}
This circle would for example appear in front of a node created on the Scene Editor with zPosition 100 例如,该圆圈将出现在使用zPosition 100在“场景编辑器”上创建的节点的前面
two things: 两件事情:
1) Im not entirely positive but I'm almost certain zPosition has to be a positive integer 1)我并不完全是正数,但我几乎可以肯定zPosition必须是正整数
2) if you want it to appear in front of a node with z position 100 than that z position has to be a number > 100 2)如果您希望它出现在z位置为100的节点的前面,则z位置必须为数字> 100
so either 所以要么
circle.zPosition = 101
or 要么
circle.zPosition = (name of what u want circle to appear in front of).zPosition + 0.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.