2012-11-21 73 views
1

我一直在研究2D遊戲風格RPG遊戲一段時間,遊戲邏輯大部分都是完成的,所以我開始嘗試讓事情看起來不錯。我注意到的一件事是走路運動/屏幕移動有點波動。從技術上講,它應該可以正常工作,但要麼它看起來有一些怪癖,要麼是因爲佔用了很多處理能力,要麼是在移動屏幕和移動精靈之間計時不一致。Cocos2d - 在平鋪地圖中的平滑雪碧運動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:位置的方法是:

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

所以setCenterOfScreen在一個乾淨莫移動攝像機而這個動作被切成兩個動作來製作動畫(我認爲這可能是效率低下的)。 很難判斷是什麼讓動作看起來不夠完美,但基本上這個人並不總是完美的屏幕的中心 - 在移動過程中,他經常像素或兩個像素一瞬間。任何想法/解決方案?

回答

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