Spritekit - Not Loading @3X Images from Sktextureatlas

SKTextureAtlas cannot be found

If you add the extension .spriteatlas to your folder name, it should work. XCode does not add this by default.

You are correct that atlases are done in the image assets folder now, William Hu's way was the old way it was done.

SpriteKit SKTextureAtlas, Terminated Due to Memory Pressure while loading texture

The file size of an image file (PNG, JPG, atlas folder, etc) tells you nothing about the memory usage.

Instead you have to calculate the texture memory usage using the formula:

width * height * (color bit depth / 8) = texture size in bytes

For example an image with dimensions 4096x4096 pixels and 32 bits color depth (4 bytes) uses this much memory when loaded as a texture (uncompressed):

4096 * 4096 * 4 = 67108864 bytes (64 Megabytes)

According to your specs (6,300 tiles, each 100x100 pixels, assuming they're all unique) you're way, wayyyyyy above any reasonable limit for texture memory usage (about 1.5 Gigabytes!). Considering the atlas size of 35 Megabytes (which is huge for an atlas btw) and assuming a mere 10:1 compression ratio you may still be looking at 350+ Megabytes of texture memory usage.

Why do my images sometimes not show in the simulator?

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.



Related Topics



Leave a reply



Submit