feat: MouseInfo now extends BaseActor

This commit is contained in:
Laureηt 2021-04-13 19:29:47 +02:00
parent fd222f1dc7
commit 41a997b1d0
3 changed files with 22 additions and 25 deletions

View file

@ -1,29 +1,25 @@
package sagittarius.model; package sagittarius.model;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
public class MouseInfo extends Actor { public class MouseInfo extends BaseActor {
// ---------- ATTRIBUTEs ----------
private BitmapFont font = new BitmapFont();
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void act(float delta) {
super.draw(batch, parentAlpha); super.act(delta);
setX(GameScreen.worldCursor.x);
font.draw(batch, "screen=" + (int)GameScreen.screenCursor.x + "," + (int)GameScreen.screenCursor.y, setY(GameScreen.worldCursor.y);
GameScreen.worldCursor.x, GameScreen.worldCursor.y + font.getCapHeight()); }
font.draw(batch, "world=" + (int)GameScreen.worldCursor.x + "," + (int)GameScreen.worldCursor.y,
GameScreen.worldCursor.x, GameScreen.worldCursor.y + font.getCapHeight()*2);
@Override
protected String getInfo() {
return
"screen=" + (int)GameScreen.screenCursor.x + "," + (int)GameScreen.screenCursor.y + "\n"
+ "world=" + (int)GameScreen.worldCursor.x + "," + (int)GameScreen.worldCursor.y
;
} }
} }

View file

@ -6,10 +6,10 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
public abstract class BaseScreen implements Screen { public abstract class BaseScreen implements Screen {
protected Stage mainStage; protected Stage mainStage;
protected Stage uiStage; protected Stage uiStage;
public BaseScreen() { public BaseScreen() {
mainStage = new Stage(); mainStage = new Stage();
uiStage = new Stage(); uiStage = new Stage();
@ -18,26 +18,26 @@ public abstract class BaseScreen implements Screen {
public abstract void initialize(); public abstract void initialize();
public abstract void update(float dt); public abstract void update(float dt);
@Override @Override
public void render(float dt) { public void render(float dt) {
// update
update(dt);
// update Stages // update Stages
uiStage.act(dt); uiStage.act(dt);
mainStage.act(dt); mainStage.act(dt);
// update
update(dt);
// clear screen // clear screen
Gdx.gl.glClearColor(0,0,0,1); Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
// draw actors on screnn // draw actors on screnn
mainStage.draw(); mainStage.draw();
uiStage.draw(); uiStage.draw();
} }
@Override public void dispose() { @Override public void dispose() {
uiStage.dispose(); uiStage.dispose();
mainStage.dispose(); mainStage.dispose();

View file

@ -59,6 +59,7 @@ public class GameScreen extends BaseScreen {
uiStage.addActor(mouseInfo); uiStage.addActor(mouseInfo);
mainStage.setDebugAll(true); // TODO: disable later mainStage.setDebugAll(true); // TODO: disable later
uiStage.setDebugAll(true); // TODO: disable later
} }