我正在创建一个安卓游戏并使用 AndEngine。背景 Sprite 移动速度在不同的设备上是不一样的,它是变化的。我正在使用下面的代码来移动 bgSprite。如何为不同的设备保持恒定的游戏速度。?
bgSprite1.setPosition(bgSprite1.getX() - 10, bgSprite1.getY());
最佳答案
创建一个扩展 Sprite 的类,例如我为我做的(shouldDie 它是一个 var,我用它来知道何时销毁 sprite(在这种情况下,当它离开屏幕时)):
public class BackgroundMovingLine extends Sprite {
public boolean shouldDie;
private int speed;
BackgroundMovingLine(final int pX,final int pY, final ITextureRegion pTextureRegion, final VertexBufferObjectManager pVertexBufferObjectManager)
{
super(pX,pY,pTextureRegion,pVertexBufferObjectManager);
shouldDie=false;
speed=(new Random()).nextInt(150)+250;
}
@Override
protected void onManagedUpdate(final float pSecondsElapsed) {
float h=this.getY();
h=(h+(speed*pSecondsElapsed));
if(h>800)
{
shouldDie=true;
}
this.setY(h);
}
}
Speed 它是移动 Sprite 的速度。 我将其设置为随机的,但您可以将其设置为您想要的。
关于android - Sprite 移动速度在所有设备上都不是恒定的 - Andengine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13154829/