Así es como lo hice:
public class ScreenIntro extends BaseScreen {
public static final String TAG = ScreenIntro.class.getName();
public ScreenIntro() {
super(RM.get().BLA_01);
BaseActor oinAvatar = new BaseActor(RM.get().TA.findRegion("oin_monk"));
oinAvatar.setOriginBasedPosition(0, 150);
mStage.addActor(oinAvatar);
Label.LabelStyle labelStyle = new Label.LabelStyle(RM.get().PRESS_START_2P_48,
RM.get().WHI_02);
Label oinLabel = new Label("OIN_ZEA", labelStyle);
oinLabel.setFontScale(.75f);
oinLabel.setPosition(
-(oinLabel.getPrefWidth() / 2),
oinAvatar.getY() - oinLabel.getPrefHeight() - 30);
oinLabel.setSize(oinLabel.getPrefWidth(), oinLabel.getPrefHeight());
mStage.addActor(oinLabel);
}
@Override
protected void onStageTouchDown(Vector2 touch, int pointer, int button) {
super.onStageTouchDown(touch, pointer, button);
concealTo(new ScreenMenu());
}
}
Y asi se ve:
La clase «BaseActor» extiende a la clase «Actor» incluida en «LibGDX» / «Scene2d» y así la codifiqué:
public class BaseActor extends Actor {
public static final String TAG = BaseActor.class.getSimpleName();
private TextureRegion textureRegion;
private final Rectangle boundingRectangle;
public BaseActor(Color color) {
setColor(color);
boundingRectangle = new Rectangle();
setTouchable(Touchable.disabled);
}
public BaseActor() {
this(Color.WHITE);
}
public BaseActor(TextureRegion textureRegion) {
this();
setTextureRegion(textureRegion);
}
public BaseActor(TextureRegion textureRegion, Color color) {
this(color);
setTextureRegion(textureRegion);
}
public BaseActor(TextureRegion textureRegion, float x, float y) {
this(Color.WHITE);
setTextureRegion(textureRegion);
setOriginBasedPosition(x, y);
}
public void setOriginBasedPosition(float x, float y) {
this.setPosition(x - this.getOriginX(), y - this.getOriginY());
}
public float getCenterX() {
return getX() + getOriginX();
}
public float getCenterY(){
return getY() + getOriginY();
}
public Rectangle getBoundingRectangle() {
boundingRectangle.set(getX(), getY(), getWidth(), getHeight());
return boundingRectangle;
}
@Override
public void setSize(float width, float height) {
super.setSize(width, height);
this.setOrigin(width / 2, height / 2);
}
public void setTextureRegion(TextureRegion textureRegion) {
this.textureRegion = textureRegion;
setOrigin(
(float)textureRegion.getRegionWidth() / 2,
(float)textureRegion.getRegionHeight() / 2);
}
public TextureRegion getTextureRegion() {
return textureRegion;
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.setColor(getColor().r, getColor().g, getColor().b, getColor().a * parentAlpha);
batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(),
getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
Para el próximo sábado, si Dios lo permite, me toca codificar una pequeña ventana que muestra información técnica como modelo de dispositivo, FPS, conteo de entidades y algunas cosas más.


Deja una respuesta