0

I used to animate my CCSprites by iterating through 30 image files (rather big ones) and on each file I changed the CCSprite's texture to that image file.

Someone told me that was not efficient and I should use spritesheets instead. But, can I ask why is this not efficient exactly?

Saturn
  • 17,888
  • 49
  • 145
  • 271

1 Answers1

0

There are two parts to this question:

  1. Memory. OpenGL ES requires textures to have width and height's to the power of 2 eg 64x128, 256x1024, 512x512 etc. If the images don't comply, Cocos2D will automatically resize your image to fit the dimensions by adding in extra transparent space. With successive images being loaded in, you are constantly wasting more and more space. By using a sprite sheet, you already have all the images tightly packed in to reduce wastage.

  2. Speed. Related to above, it takes time to load an image and resize it. By only calling the 'load' once, you speed the entire process up.

Stephen Morris
  • 289
  • 1
  • 5
  • Just as a note, most iOS devices (and all currently shipping ones) do indeed support non-power-of-two textures in both OpenGL ES 1.1 and 2.0: http://stackoverflow.com/questions/4760174/rendering-to-non-power-of-two-texture-on-iphone/4761453#4761453 . – Brad Larson Oct 01 '11 at 15:37