1

I am currently using Cocos2dx C++ version 2.0.1. I understand this is an older version of cocos2dx but I originally started using it and already made most of my game with it and I really would rather not switch versions at this time. The problem I am currently having is that my whole game has about 3 full songs, 6 sound effects, and LOTS of textures. I have about 4 sprite sheets using the .plist/.pvr approach that have about 70 frames each. Now I feel I must be doing something wrong because I feel like so many games have way more data then this and they can load up just fine. I have tried many ways to make this work efficiently. I will describe each approach and the problems I have had with each.

  1. I made A load up screen on start of the application but I found out that there seems to be no way to load .plist/.pvr asynchronously so I had no choice but to load each .PNG image one by one and no longer use sprite sheets. I feel that this is a ridiculous way but I have no found another solution. so by using this approach the game does load up (it takes some time but it does work) and since all images are preloaded the game runs smoothly. The problem here is that when I hit the home button and tap on my game icon to resume It takes a lot of time to reload all the textures and I have a very long wait before the application resumes. To fix this I have tried the following approach: I learned about setPreserveEGLContextOnPause() and how I can make textures not be lost when pressing home button. So I finally figured out how to set that up and it actually fixed the problem but I tested this with using only about a fourth of my sprites just to see how much memory it was using and I saw that it was already using 345MB of RAM! This means my full game would probably make the phone run out of RAM.

  2. After all the mishap with the first approach I am really convinced I am doing something terribly wrong because I have not seen one android game that has trouble with coming back after hitting home button. I understand I am using many sprites but I can only but them down so much. I would love to go back to using the .plist/.pvr approach but I can't seem to find a way to load these file types while presenting a loading screen.

  3. I have also tried just simply loading each thing per scenes init method. This causes the same time delay between switching scenes also.

Overall I am really stuck. I feel like I must be doing something very wrong because my game is a very simple puzzle game that is not huge by any means. I also want to find a solution that will work for iphones as well as android phones. Any help would be highly appreciated. Thanks.

  • i'm afraid to tell you that upgrading you cocos2dx at least to 2.2.3 will be very helpful to you and to your problem, because cocos2dx changed many codes related to the performance – Omar HossamEldin Jul 07 '14 at 02:51

1 Answers1

0

1* use .mp3 format for Sound. 2* load All texture in app delegate like that.

#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(  gsd->getFullPath("name.plist")->getCString()  )

#endif
#if  (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( "name.plist" );        
#endif
#if  (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)

    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile( "name.plist" );

#endif
Muhammad Noman
  • 1,566
  • 1
  • 15
  • 21