Sktextureatlas No Longer Sharing Textures in iOS 10

SKTextureAtlas no longer sharing textures in iOS 10

To get around this issue, I had to come up with a way to cache the textures so that it doesn't duplicate:

private var textureCache = [String: SKTexture]()
extension SKTextureAtlas
{
func texturesWithNames(_ names:[String]) -> [SKTexture]
{
var textures = [SKTexture]()
names.forEach({textures.append(textureNamed($0))})
return textures
}
func cachedTextureWithName(_ name:String) -> SKTexture
{
if textureCache[name] == nil
{

textureCache[name] = textureNamed(name)
}

return textureCache[name]!
}
func cachedTexturesWithNames(_ names:[String]) -> [SKTexture]
{
var textures = [SKTexture]()
names.forEach({textures.append(cachedTextureWithName($0))})
return textures
}
func clearCache()
{
textureCache = [String: SKTexture]()
}
}


extension SKTexture
{

var name : String
{
return self.description.slice(start: "'",to: "'")!
}


}

SKTextureAtlas outside app.bundle

I'm pretty sure that you can't use SKTextureAtlas like that. SKTextureAtlas accepts a name for the .atlas file and then from that obviously looks for a compiled .atlasc. You can't override this behaviour unfortunately. And if you did, Apple probably wouldn't approve it.
I think you will have to do this manually by parsing the .plist file yourself or by just using normal SKTextures.

Template Rendering is not supported in texture atlases SpriteKit and Xcode

In your assets folder, one of your textures is marked Render As:Template Image. Texture atlases do not support this render mode, so you need to change it back to Default

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.



Related Topics



Leave a reply



Submit