Cocos2D 连续滚动基于瓷砖的游戏:仅在设备中出现奇怪的闪光瓷砖、闪光、奇怪、设备

2023-09-06 09:08:35 作者:执迷不悟╮

感谢您的帮助和阅读本文.

Thanks for your helping mind and reading this.

这是我的来源:Download_Cocos2d_Continuous_Scrolling_Tile_Based_Game

它基于cocos2D 的连续滚动瓷砖游戏.在这个游戏中,tileMaps 是根据需要加载和发布的——第三个瓦片地图是当第一个被释放时加载.重复相同的过程.由于加载时间,观察到磁贴滚动中的一些混蛋.所以我使用单独的线程来加载瓷砖地图.这导致屏幕出现奇怪的闪烁......仅在设备中.

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.

如何修复此闪光灯?如何避免磁贴滚动中的小混蛋?或任何其他加载方法?

这里是加载代码:

[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];
}

推荐答案

通过异步加载 tilemap,你只是用 cocos2d 没有任何东西要渲染的短时间替换加载时间中断 - 直到加载新的 tilemap.我猜线程在这里不是一个修复,它只是给你一个相同的问题不同的症状.

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:

在需要显示新加载的 tilemap 部分之前开始线程加载某个阈值创建更小的分段拼贴图(理想情况下与屏幕尺寸一样小或稍大一些)以便加载更快将瓷砖地图预加载到内存中,但将不应该渲染的地图设置为可见 = NO

如果您不能仅仅因为它们消耗的内存而无法加载所有瓷砖地图,并且其他选项也不起作用,那么除非您可以实现自己的内存优化版本的瓷砖地图系统,否则您很不走运.

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.