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

廉价感情. 提交于 2019-12-10 08:17:56

问题


I am making an iOS using Swift and SpriteKit. 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). 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. Any ideas?


回答1:


Set the zPosition of the self.ship so that it is in front of the background nodes. 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. 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.



来源:https://stackoverflow.com/questions/33249263/swift-spritekit-skspritenodes-sometimes-dont-show-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!