summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/Label.java28
1 files changed, 19 insertions, 9 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Label.java b/core/src/ch/asynk/tankontank/game/hud/Label.java
index 2c603c6..a2cbbf4 100644
--- a/core/src/ch/asynk/tankontank/game/hud/Label.java
+++ b/core/src/ch/asynk/tankontank/game/hud/Label.java
@@ -4,14 +4,11 @@ import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
-import ch.asynk.tankontank.engine.gfx.Drawable;
-
public class Label extends Widget
{
private BitmapFont font;
- private float padding;
- private float rx;
- private float ry;
+ private float dx;
+ private float dy;
protected String text;
public Label(BitmapFont font)
@@ -21,8 +18,15 @@ public class Label extends Widget
public Label(BitmapFont font, float padding)
{
+ this(font, padding, Position.MIDDLE_CENTER);
+ }
+
+ public Label(BitmapFont font, float padding, Position position)
+ {
+ super();
this.font = font;
this.padding = padding;
+ this.position = position;
}
@Override
@@ -31,18 +35,24 @@ public class Label extends Widget
}
@Override
+ public void translate(float dx, float dy)
+ {
+ setPosition((rect.x + dx), (rect.y + dy));
+ }
+
+ @Override
public void setPosition(float x, float y)
{
TextBounds b = font.getMultiLineBounds((text == null) ? "" : text);
setPosition(x, y, (b.width + (2 * padding)), (b.height + (2 * padding)));
- this.rx = x + (padding);
- this.ry = (y + padding + b.height);
+ this.dx = (x + padding);
+ this.dy = (y + padding + b.height);
}
public void write(String text)
{
this.text = text;
- setPosition(rect.x, rect.y);
+ setPosition(position);
}
public void write(String text, float x, float y)
@@ -55,6 +65,6 @@ public class Label extends Widget
public void draw(Batch batch)
{
if (!visible) return;
- font.drawMultiLine(batch, text, rx, ry);
+ font.drawMultiLine(batch, text, dx, dy);
}
}