创建一个扩展 Sprite 的类,例如我为我做了这个(应该是一个 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);
}
}
速度它是移动精灵的速度。我是随机的,但你可以将它设置为你想要的。