2016-05-17 74 views
0

我的遊戲是一個平臺遊戲,屏幕會跟隨不斷移動到底層的玩家。遊戲每秒都會減慢運動速度,然後再次加速。我將如何阻止這種情況的發生。我已經將德爾塔時間傳遞給了我的世界,但他們並沒有幫助滯後或口吃。由於Libgdx遊戲加速並每秒減速

主要呈現循環

public void update(float dt){ 
     world.step(1/60f, 2, 2); 

     handleInput(dt); 

     camX(); 

     player.moveMario(); 

     hud.update(); 

     gameCam.update(); 
     renderer.setView(gameCam); 
    } 

    @Override 
    public void render(float delta) { 
     update(delta); 
     Gdx.gl.glClearColor(0, 0, 0, 1); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 

     renderer.render(); 

     game.batch.setProjectionMatrix(hud.stage.getCamera().combined); 
     hud.stage.draw(); 

     game.batch.setProjectionMatrix(gameCam.combined); 
     game.batch.begin(); 
     game.batch.draw(ball, player.b2Body.getPosition().x - MarioBros.RADIUS_CHARACTER/MarioBros.PPM, player.b2Body.getPosition().y - MarioBros.RADIUS_CHARACTER/MarioBros.PPM, 70/MarioBros.PPM, 70/MarioBros.PPM); 
     mapCreator.createSpikeBalls(map, animation, game.batch); 
     endOfGame(); 
     game.batch.end(); 

     b2dr.render(world, gameCam.combined); 
    } 

    public void camX(){ 
      gameCam.position.x = gamePort.getWorldWidth()/2; 
      if(player.b2Body.getPosition().x >= gamePort.getWorldWidth()/2){ 
       gameCam.position.x = player.b2Body.getPosition().x; 
      } 
    } 

角色的移動到右側

public void moveMario(){ 
     if (b2Body.getLinearVelocity().x < 4){ 
      b2Body.applyLinearImpulse(new Vector2(2.7f, 0), b2Body.getWorldCenter(), true); 
     } 
    } 
+0

我不知道到底是什麼你'w^orld.step()'在做,但是這聽起來像可能需要delta時間的那種函數 – rbennett485

回答

1

不是你寫你的世界和身體設置什麼,但我猜測,以下情況發生:

  • 您應用的衝動馬里奧=>他的速度增加
  • 在以下幾世的步驟,身體摩擦只要b2Body.getLinearVelocity().x < 4是真的減慢馬里奧下來
  • ,你再衝動適用於馬里奧
  • 摩擦減慢他下來了
  • ...

除此之外,你一定要傳遞的DeltaTime世界的步法