John Rake
John Rake

Reputation: 75

Why do my images sometimes not show in the simulator?

I'm working on a game with just a few screens at the moment. I've added a few sprite textures to my scenes as shown below.

Why aren't my images consistently loading in the simulator?

Dashboard Scene File

Dashboard Simulator Try 1

This was one attempt to load the application in the iOS simulator. As you can see a number of images aren't being loaded in this instance from the spritekit scene file above.

Dashboard Simulator Try 2

Below is one another attempt to load the dashboard scene within a simulator. The resulting view is drastically different and yet no code was changed. I don't understand how the images being rendered can vary like this.

Upvotes: 2

Views: 489

Answers (2)

Ron Myschuk
Ron Myschuk

Reputation: 6061

from Apple

The default value is 0.0. The positive z axis is projected toward the viewer so that nodes with larger z-position values are closer to the viewer. When a node tree is rendered, the height of each node (in absolute coordinates) is calculated and then all nodes in the tree are rendered from smallest z-position value to largest z-position value. If multiple nodes share the same z-position, those nodes are sorted so that parent nodes are drawn before their children, and siblings are rendered in the order that they appear in their parent’s children array. Hit-testing is processed in the opposite order.

The SKView class’s ignoresSiblingOrder property controls whether node sorting is enabled for nodes at the same z-position.

Basically by setting them all to 0 you are taking a random chance that they are going to layout in the order that you want them to. You can try setting the ignoresSiblingOrder to see if you actually have them placed in the code in the correct order and see if they will present in the proper order.

But I would strongly recommend you place them in a structured layer z order versus doing that.

ie.

background.zPosition = 0
hero.zPosition = 1
scoreLabel.zPosition = 500

Again from Apple regarding the ignoresSiblingOrder

The default value is false, which means that when multiple nodes share the same z position, those nodes are sorted and rendered in a deterministic order. Parents are rendered before their children, and siblings are rendered in array order. When this property is set to true, the position of the nodes in the tree is ignored when determining the rendering order. The rendering order of nodes at the same z position is arbitrary and may change every time a new frame is rendered. When sibling and parent order is ignored, SpriteKit applies additional optimizations to improve rendering performance. If you need nodes to be rendered in a specific and deterministic order, you must set the z position of those nodes.

Upvotes: 2

George_E -old
George_E -old

Reputation: 188

  • Make sure every image is visible:

    myImage.alpha = 1
    
  • That you have correctly typed in EXACTLY (capital letters, spaces etc.) the correct image name

  • The image is in your assets folder

  • Your image is not being compressed by other images

Upvotes: 0

Related Questions