Hi, I’m on the way to finish my first game, but now I ran into little problem.
The scheme is this: Main menu scene > Level select scene> Loading scene -> Game scene. On loading scene I preload all resources like sprites, sounds, etc. But one of my test devices (HTC Desire, Android 2.2.2) unloads resources after loading, so when the game tries to play some sound or draw sprite, it freezes for a moment to load the resource again.
This problem appers only on HTC Desire, I didn’t met this problem on my other devices (Samsung Galaxy Ace, Android 2.3.6 & Acer A100 tab, Android 4.0.3).
Try disabling sounds and if it still freezes - try adding sprite frames from your sprite sheets (assuming that you’re using them) to CCSpriteFrameCache before you go to scene.
I really wonder what are you going to do with 100 mb of textures…
Normally there are only two possibilities for resources to be unloaded: if you do it by your hand and if app gets memory warning. Otherwise such “automatic unloading” should be considered as a bug, because it obviously will cause crashes.
Try disabling sounds and if it still freezes - try adding sprite frames from your sprite sheets (assuming that you’re using them) to CCSpriteFrameCache before you go to scene.
>
I really wonder what are you going to do with 100 mb of textures…
When you call addImage method you only start the process and you don’t actually know when it will end, and depending on your device loading textures can take different amounts of time. Try using addImageAsync - that method allows you to get a callback after everything is loaded. You can easily find a sample in TestCpp. The scheme is as follows:
start loading N textures > show smth like LOADING…> get N callbacks > addSpriteFrame> proceed further
OK, guys, thank you all, I’ve finally found the solution for my problem. Maybe it’s kinda stupid, but I don’t see the other way.
I simply create a sprite for each texture and append all of this sprites as children to the loading screen
Yes, I’ve tried everything that has been said in this thread. I think (maybe) the cause of problem is android 2.2 garbage collector.
The most helpful advice was to upgrade cocos2dx to latest version, it helped me with another bug, but it is another story. Thank you, comrad
Here you assume that loading of one resource file takes exactly 1/60 of a second which is obviously not true in a common case - you just don’t know how long will it take for a resource to load, because it depends on the hardware and current memory state. I think If you’ll dump texture cache before going to another scene you will clearly see that some resources are missing. Try switching to loadImageAsync() - with it you can be sure that all resources are loaded properly.