我的图像必须在5秒钟内从屏幕的顶部下降到屏幕的底部。该动作可以在台式机和智能手机上流畅运行,但不能在Galaxy Tab S2上运行。
public class MyImage extend Actor {
float fallingSpeed = 0;
public void act(float delta)
{
setY(getY() - fallingSpeed * delta);
}
public void setFallingSpeed(float t)
{
this.fallingSpeed = t;
}
当以恒定值(1)下降时,动画将变得平滑,但是我更喜欢以更可定义的方式指定速度的方法,例如上面的fallingSpeed的定义,还想知道运动不均匀的原因。
gameScreen类代码:
//inside game screen class
float increaseSpeedDuration = 1;// increase falling speed after one second
float increaseSpeedValue = Gdx.graphics.getHeight()/60;
float globalFallingSpeed = Gdx.graphics.getHeight()/5;
private void updateFallingSpeed(float dt) {
increaseSpeedTimer += dt;
if(increaseSpeedTimer > increaseSpeedDuration )
{
increaseSpeedTimer = 0;
globalFallingSpeed += increaseSpeedValue;
myImage.setFallingSpeed(globalFallingSpeed); // setFallingSpeed will change the fallingSpeed value inside my image class.
}
}
public void render(float delta)
{
updateFallingSpeed(delta);
}
有帮助吗?