开发者

About animating frame by frame with sprite files

开发者 https://www.devze.com 2023-04-09 11:03 出处:网络
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.

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 to开发者_运维知识库ld me that was not efficient and I should use spritesheets instead. But, can I ask why is this not efficient exactly?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号