Lo único nuevo, en cuanto a código se refiere, es el uso de «CheckBox» de la librería «LibGDX.Scene2d.UI» y las líneas animadas por decoración (TiledLine).
La clase «TiledLine.java» solo maneja un arreglo de actores extendidos por la clase «BaseAnimatedActor.java».
public class BaseAnimatedActor extends Actor {
private float stateTime;
private final Animation<TextureRegion> animation;
public BaseAnimatedActor(Animation<TextureRegion> animation, float stateTime) {
this.animation = animation;
this.stateTime = stateTime;
float width = animation.getKeyFrame(0).getRegionWidth();
float height = animation.getKeyFrame(0).getRegionHeight();
setBounds(getX(), getY(), width, height);
setOrigin(width / 2, height / 2);
}
}
Para animar las entidades o lozas, como las llamo, añado la línea 51 en el método de «act».
@Override
public void act(float delta) {
super.act(delta);
stateTime += delta;
}
Después, añado las líneas 58, 60 y 62 en el método «draw» para dibujar las lozas en pantalla.
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
TextureRegion currentFrame = animation.getKeyFrame(stateTime, true);
batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a * parentAlpha);
batch.draw(currentFrame, getX(), getY(), getOriginX(), getOriginY(),
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
Y así se ve:


Deja una respuesta