简体   繁体   English

Swift SpriteKit SKSpriteNode的“有时”不会出现

[英]Swift SpriteKit SKSpriteNode's “Sometimes” Don't Show Up

I am making an iOS using Swift and SpriteKit. 我正在使用Swift和SpriteKit制作iOS。 However I am experiencing irregularity in the running of my app. 但是我在运行我的应用程序时遇到了不正常现象。 Sometimes the ship SKSpriteNodes doesn't appear on the screen, sometimes the bullet's SKSpriteNodes don't appear, sometimes everything shows up fine (I add the bullets elsewhere in the code). 有时船只SKSpriteNodes没有出现在屏幕上,有时子弹的SKSpriteNodes没有出现,有时一切都显示正常(我在代码的其他地方添加了子弹)。 In all cases I am not making changes to the code between runs. 在所有情况下,我都没有在运行之间更改代码。 I am starting the app on this screen directly so I'm thinking maybe it has something to do with these SKSpriteNodes not having enough time to initialize. 我正在这个屏幕上直接启动应用程序,所以我想也许它与这些没有足够时间初始化的SKSpriteNodes有关。 Any ideas? 有任何想法吗?

Set the zPosition of the self.ship so that it is in front of the background nodes. 设置zPositionself.ship ,使其位于后台节点的前面。 Something like this (I would do this after setting the position): 这样的事情(我会在设定位置后这样做):

self.ship.zPosition = 1.0

You can also use negatives in the zPosition , for instance, to drop the self.background down. 例如,您也可以在zPosition使用底片来放下self.background Think of zPosition as layers (with support for decimals), the higher the number, the closer to the "top" of the layer stack your node will be. zPosition视为图层(支持小数),数字越大,您的节点将越接近图层堆栈的“顶部”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM