2

I am having trouble understanding why my app that has a lot of resources is taking a long time to startup (NOT to load the resources. The program does NOT load many resources at startup).

To clarify (and I did this to confirm that the problem was related to the number of resources in my resource bundle):

  1. I created a new cocos2d project.
  2. Then I took helloWorldLayer from the newly created project and put it in MY APP which had a lot of resources (thousands of small pngs).
  3. In MY APPs appDelegate I then ran this layer (scene) instead of the scene it would usually load (which would have been MainMenu). The output is exactly the same as the cocos2d template. The cocos2d default.png followed by "hello world."
  4. However, it takes a lot longer to startup MY APP than the cocos2d project and also to change from the default.png loading screen to the actual code ("Hello World");

Is this expected behavior? Why is there a difference?

Naseiva Khan
  • 965
  • 1
  • 7
  • 15
  • 1
    Are you loading assets into the sprite frame cache in your app delegate? – Ben Trengrove Jan 08 '13 at 04:26
  • 2
    I updated my question because it was unclear I think. – Naseiva Khan Jan 08 '13 at 12:16
  • Check that you're really not loading any resources. Perhaps you think you don't load them but maybe you do? Check with instruments to see if memory usage goes up, or set a breakpoint in the usual suspects (mainly texture cache). – CodeSmile Jan 08 '13 at 23:14
  • 1
    @LearnCocos2D: So to test this, I created a brand new cocos2d project, compiled it and saw that it ran fine. Without writing a character of code, I added the resources from the other project and . . . same result: a pause before default.png came up and a shorter pause before the code ran: "Hello World". Now I wish I had listened to you earlier and used texture atlases (120 monsters x 80 frames = 12000 .png files alone and the number will go up to 360 monsters during app lifetime!). I calculate it will take 20+ solid hours to convert to using texture atlases. – Naseiva Khan Jan 09 '13 at 12:12
  • 1
    Player .pngs amount to about 13000 files as well, because of all the different equipment that can be worn, so my total resources is about 25000 files. I guess ios goes through a quick verification process or something before loading an app? – Naseiva Khan Jan 09 '13 at 12:16

1 Answers1

0

Use threaded loading in cocos2d game. Make sure you loaded resource certain threshold before the newly loaded resource is used. Here is my own question and solved now. There is one thread sample in cocos2d sdk..you can refer that also.

[NSThread detachNewThreadSelector:@selector(loadingThread:) toTarget:self withObject:nil];

-(void)loadingThread:(id)argument
{
    NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
    CCGLView *view = (CCGLView*)[[CCDirector sharedDirector] view];
    EAGLContext *auxGLcontext = [[EAGLContext alloc]
                                 initWithAPI:kEAGLRenderingAPIOpenGLES2
                                 sharegroup:[[view context] sharegroup]];

    if( [EAGLContext setCurrentContext:auxGLcontext] ) {

        [self loadGameResource];

        glFlush(); 

        [EAGLContext setCurrentContext:nil];
    } else {
        CCLOG(@"cocos2d: ERROR: TetureCache: Could not set EAGLContext");
    }

    [auxGLcontext release];

    [autoreleasepool release];
}
Community
  • 1
  • 1
Guru
  • 21,652
  • 10
  • 63
  • 102
  • 1
    I updated my question because it was unclear I think. The question is not related to loading of resources, but resource bundle size. I implement lazy loading always so I never have a lot of resources loading at once, except at actual gameplay entry (ie. when the level is loading) and I use a progress timer to indicate to the user the level is now loading. – Naseiva Khan Jan 08 '13 at 12:19