diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:39:33 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:39:33 +0100 |
commit | 197b754359748320975c013daaf3cc6c4ff6f37a (patch) | |
tree | db158724ae4bf3b0c1c8f664092f7fa493d46f85 /core/src | |
parent | 025855819d8052410bc8bbc2c62016211a3c99d2 (diff) | |
download | RustAndDust-197b754359748320975c013daaf3cc6c4ff6f37a.zip RustAndDust-197b754359748320975c013daaf3cc6c4ff6f37a.tar.gz |
LabelImage, extends Bg, use Position to set Label position
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/LabelImage.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/LabelImage.java b/core/src/ch/asynk/tankontank/game/hud/LabelImage.java index 4eb14c7..3081d7f 100644 --- a/core/src/ch/asynk/tankontank/game/hud/LabelImage.java +++ b/core/src/ch/asynk/tankontank/game/hud/LabelImage.java @@ -3,40 +3,46 @@ 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.TextureRegion; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import ch.asynk.tankontank.engine.gfx.Image; - -public class LabelImage extends Image +public class LabelImage extends Bg { private Label label; + public Position labelPosition; + + public LabelImage(TextureRegion region, BitmapFont font) + { + this(region, font, 0f); + } - public LabelImage(TextureRegion region, BitmapFont font, String text) + public LabelImage(TextureRegion region, BitmapFont font, float padding) { super(region); - this.label = new Label(font, text); + this.label = new Label(font, padding); + this.labelPosition = Position.MIDDLE_CENTER; } @Override public void dispose() { - super.dispose(); label.dispose(); } - public void setPosition(float x, float y) + public void setLabelPosition(Position position) { - super.setPosition(x, y); - setLabelPosition((x + ((getWidth() - label.getWidth()) / 2)), (y + ((getHeight() - label.getHeight()) / 2))); + labelPosition = position; } - public void setLabelPosition(float x, float y) + public void setPosition(float x, float y) { - label.setPosition(x, y); + set(x, y, getWidth(), getHeight()); + label.setPosition(labelPosition.getX(this, label.getWidth()), labelPosition.getY(this, label.getHeight())); } public void write(String text) { this.label.write(text); + setPosition(getX(), getY()); } @Override @@ -46,4 +52,12 @@ public class LabelImage extends Image super.draw(batch); label.draw(batch); } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!visible) return; + super.drawDebug(shapes); + label.drawDebug(shapes); + } } |