2013-05-30 57 views
-6

我是'andengine'的新手,我開發像'mario'這樣的簡單遊戲,所以我想跳轉並以合適的方式移動該角色。如何跳躍和動畫像馬里奧遊戲角色的身體?

請給我一些想法,我使用速度和衝動,但不能正常工作。

+2

你可以發表你有什麼atm? – wesdfgfgd

+0

我不知道atm是什麼意思? – Kiran

+0

「我是新人」和「我想要」在這裏提出問題的方式並不合適,發佈代碼有很大幫助。 – Mateusz

回答

2

AndEngineExamples項目包含幾個與您的應用程序類似的示例遊戲。 在挖掘代碼之前,您可以先下載APK並試用。

AndEngineExamples

1

以下是我做到了(我的界面我的播放器類):

public void moveLeft() { 
    Vector2 velocity = Vector2Pool.obtain(-speed, body.getLinearVelocity().y); 
    body.setLinearVelocity(velocity);     
    Vector2Pool.recycle(velocity); 

    int offset = isInjured ? 4 : 0;  
    if (!isAnimationRunning()) { 
     setCurrentTileIndex(2 + offset); 
     animate(new long[]{200, 200}, 2 + offset, 3 + offset, 1, animationListener);  
    } 
} 

public void moveRight() { 
    Vector2 velocity = Vector2Pool.obtain(speed, body.getLinearVelocity().y); 
    body.setLinearVelocity(velocity);    
    Vector2Pool.recycle(velocity); 

    int offset = isInjured ? 4 : 0; 
    if (!isAnimationRunning()) { 
     setCurrentTileIndex(0 + offset); 
     animate(new long[]{200, 200}, 0 + offset, 1 + offset, 1, animationListener);   
    } 
} 

public void stop() { 
    Vector2 velocity = Vector2Pool.obtain(0, body.getLinearVelocity().y); 
    body.setLinearVelocity(velocity);     
    Vector2Pool.recycle(velocity); 

    stopAnimation(); 

    int offset = isInjured ? 4 : 0; 
    if(getCurrentTileIndex() % 4 > 1) 
     setCurrentTileIndex(2 + offset); 
    else 
     setCurrentTileIndex(0 + offset); 
} 

public void stopJump() { 
    if(jumpsLeft > 0) { 
     Vector2 velocity = Vector2Pool.obtain(body.getLinearVelocity().x, body.getLinearVelocity().y/5); 
     body.setLinearVelocity(velocity);     
     Vector2Pool.recycle(velocity); 
    } 
} 

public void jump() { 
    if(jumpsLeft > 0) { 
     Vector2 impulse = Vector2Pool.obtain(0, body.getMass() * -12); 
     body.applyLinearImpulse(impulse, body.getWorldCenter());     
     Vector2Pool.recycle(impulse); 
     jumpsLeft--; 
    } 
} 

然後,我創建的按鈕用於移動左,右,跳躍等 在AreaTouched事件,爲了採取行動,我做了player.jump()。 爲了採取行動,我做了player.stopJump()。 move_left和move_right按鈕的代碼幾乎相同。