Stephen
Stephen

Reputation: 499

Cocos2d Loading several images at once?

I have been searching the cocos2d forum but I do not understand some of the concepts the people are using. In my game I am having to load over 100 images to use as an animation for my main menu but the problem that I am having is these images take about 3 to 5 seconds to load and then my game starts up. The animation runs great after the images are loaded but it's the loading that is the problem. I would use sprite sheets but the images are to big so I have to load them separately. So should I make a loading screen to load all of these images in first and if so how is the best way to implement this? This is my first time of trying to do something like this.

Upvotes: 0

Views: 503

Answers (2)

YvesLeBorg
YvesLeBorg

Reputation: 9089

@Stephen : Two ways to do this. With TexturePacker you can create a .tps file, one for each source image, then under File->Export Image. Set the geometry to 1024x1024 for your images. Specify .pvr format, enable pre-multiplied alpha, and toy with dithering (this may actually benefit some textures, ie improve on .png's). You could also probably benefit from RGBA4444 for menus (gain on memory required, with no significant loss on rendered quality).

You can also use the builtin texturetool as follows:

before you do this, you must convert toto.png to a POT file (1024x1024) in your case, with photoshop for example.

MrEvil:pvrCenter$ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -m -f PVR -e PVRTC toto.png -o toto.pvr

MrEvil:pvrCenter$ gzip toto.pvr

this gives excellent compressions after a gzip (from 691Kb png to 295Kb).

I used texturetool because i can script that in shell, and process a whole lot of images with a single command (play D3 while the box churns out the images :) ).

EDIT 1 : some info on packing and file sizes.

ok, i started with one of my own 960x640 8 bits PNG, 691 Kb.

load it TexturePacker, set format to RBGA8888, 1024x1024, i get 766 Kb (this gives my my POT file).

export to RGBA8888 as a .pvr.ccz, 996 Kb. export to RGBA8888 as a .pvr.gz, 1.001 Mb export to RGBA4444 as a .pvr.ccz, 193Kb.

if i use texturetool on the 766 Kb file, then gzip the file 305Kb (RGBA8888). I cant really explain the difference between 305Kb and 996 Kb. It could be related to the dithering processing by TexturePacker, not certain.

Upvotes: 1

CodeSmile
CodeSmile

Reputation: 64477

Yes, definitely use a texture atlas (sprite sheet is not the correct term but means the same thing). A great tool for that is TexturePacker.

A texture atlas will save time when loading, and conserve memory. You can also try out different image color depth and compression options to further improve memory usage and loading times, but many options will affect image quality to a varying degree and depending on your images.

Btw, how big are these images? Assuming each is 512x512, and you load 100 of them, they'll consume 100 MB of memory. I mention that because this is often overlooked, and file sizes on disk are a fraction of what the images consume as textures.

Upvotes: 0

Related Questions