1

Thanks for your helping mind and reading this.

Here is my source: Download_Cocos2d_Continuous_Scrolling_Tile_Based_Game

Its continuously scrolling tile based cocos2D game. In this game, tileMaps are loaded and released on need basis - 3rd tile map is loaded when 1st one is released. Same process is repeated. Observed some jerk in tile scroll because of loading time. So I used separate thread to load tile map. That caused strange flash in screen..only in device.

  1. How can I fix this flash?
  2. How can I avoid little jerk in tile scroll? or any alternative method for loading?

Here is loading Code:

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


-(void)loadTileMapInThread:(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 LoadTilesMap];

        glFlush(); //whn I comment this also..flash observed

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

    [auxGLcontext release];

    [autoreleasepool release];
}
Charles
  • 50,943
  • 13
  • 104
  • 142
Guru
  • 21,652
  • 10
  • 63
  • 102

1 Answers1

2

By loading the tilemap asynchroneously you are merely replacing the loading time interruption with a short time where cocos2d doesn't have anything to render - until the new tilemap is loaded. I'm guessing threading is not a fix here, it just gives you a different symptom for the same problem.

I think the ways you can fix this is by:

  • start threaded loading a certain threshold before the newly loaded tilemap section needs to be displayed
  • creating smaller subsection tilemaps (ideally as small as screensize or a bit larger) so they load faster
  • preload tilemaps into memory, but set visible = NO for those which aren't supposed to be rendered

If you can't load all tilemaps simply due to the memory they consume and the other options won't work either you're out of luck unless you can implement your own, memory-optimized version of a tilemap system.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217