我的 deltaTIme 遇到了麻烦,基本上我想做的就是每秒向变量添加 1。
private int num=0
private float deltaTime=Gdx.graphics.getDeltaTime();
public void render(){
deltaTime=Gdx.graphics.getDeltaTime();// updating
num += 1*deltaTime;
System.out.println(num);
}
输出是这样的
0
0.016612083 //it does not add 1 to num every second
0
0.016679354
0
0.016680228
0
0.016672073
0
最佳答案
LibGDX 的 deltaTime
是一个 float
以及自上一帧以来耗时量(以秒为单位)。
您需要一个 float
变量来跟踪时间,因为 int
在这里不起作用。
float timePassed = 0f;
public void render() {
timePassed += Gdx.graphics.getDeltaTime();
if (timePassed >= 1f) {
// one second has passed and you can do something
}
}
关于java - DeltaTime 未正确更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32646302/