pre-loading assets (image and music) ??


#1

I found a good article on how to pre-load assets (image and music) with cocos2d-iPhone, but can someone please help me translate this to something that will work with android and iPhone? Do I need to implement threading to pre-load assets?

cocos2d-iphone article:
[[http://xperienced.com.pl/blog/how-to-preload-your-game-assets-in-loading-scene]]

Thanks
ML


#2

No threading needed, just pre-load using the command at the start of your app; e.g to load a sound:

SimpleAudioEngine::sharedEngine()->preloadEffect( “my_sound.wav” );

… and to play it…

CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( “my_sound.wav” );


#3

So the game UI will update even as image and audio resources are being loaded?


#4

Kind of….

If you don’t pre-load say for example your “bang.wav” sample, then try and play it during your game some time later with “playEffect(”bang.wav“), the game will pause for say a tenth of a second whilst the sample is loaded (only for the first time you play the sample, but this”pause" isn’t ideal). To stop the pause happening you need to preload the sample before you start your main game loop, then you can use “playEffect” anytime with no pause as the sample is already in memory.


#5

So then if I wanted a loading screen that had the percentage loaded updating, or an animation playing while all of my assets are loading I can’t do that because of the pause??


#6

Here’s how I’m doing it: I create a list of files to preload. I have a loading scene and I load one file per frame (no multithreading). I only put a simple CCProgressTimer on the scene and updates the loadong percentage depending on the remaining files to load. Of course, it’s not very smooth (especially when loading big textures) but I think it’s simple and good enough for the player.


#7

Hello Frozax, according to your progress bar’s percentage, Do you actually check for successful loading?
I want to know how to hook to receive the successful loading event for each resource. I think update the percentage of overall loading progress for the beginning of loading for each resource is simpler and doesn’t need any hooking events, but that’s not accurate enough.