【发布时间】:2016-05-17 18:59:13
【问题描述】:
我的游戏是一个平台游戏,屏幕会跟随不断在背景中移动的玩家。游戏每秒都会减慢向右的移动速度,然后再次加速。我将如何阻止这种情况发生。我已经通过 delta time 进入我的 world.step 但他们没有帮助滞后或口吃。谢谢
主渲染循环
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);
}
}
【问题讨论】:
-
我不确定你的
world.step()到底在做什么,但这听起来像是那种可能也需要增量时间的函数
标签: libgdx