问题
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