0

I have 100 textures, each sized ~100 kb, and I want to create a SKAction with animating these textures for 4 seconds with 25fps, and looping the action forever. I'm loading them from an atlas (or several, as Xcode warns me that it splits the atlas into 9).

The problem is the memory usage increases from 4 to 150 mb's when I run the action. Everything's normal in the first three steps. Total size of the assets is ~12 mb.

Can the multi-atlas usage (Xcode splitting them on compile time) can cause this problem?

// Load the frames to an array
NSArray *sTreesRightAnimationFrames = ITBLoadFramesFromAtlas(@"s01-trees-right", @"s01-trees-right-", 100);
// Create the action
SKAction *sTreesRightAction = [SKAction animateWithTextures:sTreesRightAnimationFrames timePerFrame:1.0f / 25.0f];
// Create the forever action
SKAction *sTreesRightForeverAction = [SKAction repeatActionForever:sTreesRightAction];

// Preload the textures and run the action
[SKTexture preloadTextures:sTreesLeftAnimationFrames withCompletionHandler:^{
    [treesLeft runAction:sTreesLeftForeverAction];
}];
emrekyv
  • 1,256
  • 1
  • 18
  • 21
  • With very large textures, it will not make any difference to put them in an atlas vs a PNG image for each frame. What you could do is reduce the in memory size of the textures http://stackoverflow.com/a/38679128/763355 – MoDJ Jul 31 '16 at 19:59

1 Answers1

3

Sizes are filesizes, I presume? Because they don't tell you how much memory the texture from a given image will use. To calculate that for any given (atlas) image, use:

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

For example:

1024 x 1024 x (32 / 8) = 4194304 Bytes = 4 Megabytes
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Yes, they are filesizes. In that case, everything checks out. In that case, I need to find a better way to animate these textures. – emrekyv Dec 04 '13 at 21:59