且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用libgdx加快游戏速度

更新时间:2023-01-31 09:04:57

使用delta.

Gdx.graphics.getDeltaTime()方法返回自上一个渲染帧以来的秒数.通常,此值非常小,等于1/FPS.

Gdx.graphics.getDeltaTime() method return secods since last render frame. Usually this value is very small, and it equal 1 / FPS.

@Override
public void render() 
{
    // limit it with 1/60 sec
    float dt = Math.min(Gdx.graphics.getDeltaTime(), 1 / 60f); 
    // then move your characted according to dt
    player.pos = player.pos + player.speed * dt;
    // or, you could mute the speed like this:
    player.pos = player.pos + player.speed * dt * 0.85;
}