1

我一直在研究 2-D Gameboy 风格的 RPG 一段时间,游戏逻辑大部分都完成了,所以我开始尝试让事情看起来不错。我注意到的一件事是步行运动/屏幕运动有点不稳定。从技术上讲,它应该可以正常工作,但要么它似乎有一些怪癖,要么是由于占用了大量的处理能力,要么是移动屏幕和移动精灵之间的时间不一致。

要移动精灵,一旦我知道要移动它的位置,我会调用:

tempPos.y += 3*theHKMap.tileSize.width/5; 
id actionMove = [CCMoveTo actionWithDuration:0.1 position:tempPos]; 
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(orientOneMove)];
[guy runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
[self setCenterOfScreen:position];

然后,在 orientOneMove 中,我调用:

[self.guy setTexture:[[CCTextureCache sharedTextureCache] addImage:@"guysprite07.png"]]; //the walking picture-I change texture back at the end of the movement
id actionMove = [CCMoveTo actionWithDuration:0.15 position:self.tempLocation2];
id actionMoveDone = [CCCallFuncN actionWithTarget:self selector:@selector(toggleTouchEnabled)];
[guy runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];

并发运行的 setCenterOfScreen:position 方法的代码是:

id actionMove = [CCMoveTo actionWithDuration:0.25 position:difference]; [self runAction:
[CCSequence actions:actionMove, nil, nil]];

因此,当setCenterOfScreen移动的人被分成两个动作来制作动画时,摄像机以一个干净的动作移动(我认为这可能效率低下。)很难说是什么使运动不完全干净,但本质上是家伙并不总是完美地位于屏幕的中心——在移动过程中,他经常会瞬间偏离一两个像素。任何想法/解决方案?

4

1 回答 1

1

使用可以解决您的问题的线程加载。参考这篇文章:cocos2d-continuously-scrolling-tile-based-game可能是有用的提示

[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(); 

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

    [auxGLcontext release];

    [autoreleasepool release];
}
于 2012-11-21T05:38:10.257 回答