From bcc59be0f6af5dcab805ed0fa251bbc4bda05742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 4 Nov 2014 11:28:47 +0100 Subject: add game/hud/TextButton --- .../ch/asynk/tankontank/game/hud/TextButton.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/game/hud/TextButton.java diff --git a/core/src/ch/asynk/tankontank/game/hud/TextButton.java b/core/src/ch/asynk/tankontank/game/hud/TextButton.java new file mode 100644 index 0000000..158a2b0 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/TextButton.java @@ -0,0 +1,47 @@ +package ch.asynk.tankontank.game.hud; + +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; + +public class TextButton extends Button +{ + private Text text; + + public TextButton(TextureAtlas atlas, String base, BitmapFont font, String text) + { + super(atlas, base); + this.text = new Text(font, text); + } + + @Override + public void dispose() + { + super.dispose(); + text.dispose(); + } + + public void setPosition(float x, float y) + { + super.setPosition(x, y); + setTextPosition((x + ((getWidth() - text.getWidth()) / 2)), (y + ((getHeight() - text.getHeight()) / 2))); + } + + public void setTextPosition(float x, float y) + { + text.setPosition(x, y); + } + + public void write(String text) + { + this.text.write(text); + } + + @Override + public void draw(Batch batch) + { + if (!visible) return; + super.draw(batch); + text.draw(batch); + } +} -- cgit v1.1-2-g2b99