Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift SpriteKit SKSpriteNode's "Sometimes" Don't Show Up

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?

like image 670
mpkostek Avatar asked Dec 04 '22 02:12

mpkostek


1 Answers

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.

like image 113
Gliderman Avatar answered Dec 10 '22 12:12

Gliderman