我正在製作一個遊戲,玩家(「Bob」)垂直移動並持續收集硬幣。如果玩家沒有設法收集任何硬幣5秒,「鮑勃」開始下降。隨着時間的推移,他會更快地倒下。我如何跟蹤Java第三方API「LibGDX」中的流逝時間?
我的問題是這樣的:如何跟蹤LibGDX(Java)應用程序中的流逝時間?
示例代碼如下。
public void update (float deltaTime)
{
`velocity.add(accel.x * deltaTime,accel.y*deltaTime);`
position.add(velocity.x * deltaTime, velocity.y * deltaTime);
bounds.x = position.x - bounds.width/2;
bounds.y = position.y - bounds.height/2;
if (velocity.y > 0 && state == BOB_COLLECT_COINE)
{
if (state== BOB_STATE_JUMP)
{
state = BOB_STATE_Increase;
stateTime = 0;
}
else
{
if(state != BOB_STATE_JUMP)
{
state = BOB_STATE_JUMP;//BOB_STATE_JUMP
stateTime = 0;
}
}
}
if (velocity.y < 0 && state != BOB_COLLECT_COINE)
{
if (state != BOB_STATE_FALL) {
state = BOB_STATE_FALL;
stateTime = 0;
}
}
if (position.x < 0) position.x = World.WORLD_WIDTH;
if (position.x > World.WORLD_WIDTH) position.x = 0;
stateTime += deltaTime;
}
public void hitSquirrel()
{
velocity.set(0, 0);
state = BOB_COLLECT_COINE;s
stateTime = 0;
}
public void collectCoine()
{
state = BOB_COLLECT_COINE;
velocity.y = BOB_JUMP_VELOCITY *1.5f;
stateTime = 0;
}
,並呼籲在世界級的collectmethod在upate作爲鮑勃 -
private void updateBob(float deltaTime, float accelX)
{
diff = collidetime-System.currentTimeMillis();
if (bob.state != Bob.BOB_COLLECT_COINE && diff>2000) //bob.position.y <= 0.5f)
{
bob.hitSquirrel();
}
你是對的我沒想過 – Tiarsoft 2013-08-04 00:59:37