diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-15 17:24:34 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-10-15 17:24:34 +0200 |
commit | 76f7f3d377279d3d2a72cf5985e028e2a6cfdf9c (patch) | |
tree | 08d330e5227600f44de02586db80272ba38b0345 | |
parent | a043f7be9a33ec9f5aa57e18b1ae26878496720c (diff) | |
download | RustAndDust-76f7f3d377279d3d2a72cf5985e028e2a6cfdf9c.zip RustAndDust-76f7f3d377279d3d2a72cf5985e028e2a6cfdf9c.tar.gz |
add Hud/Msg
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Msg.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Msg.java b/core/src/ch/asynk/tankontank/game/hud/Msg.java new file mode 100644 index 0000000..c5b72b5 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/Msg.java @@ -0,0 +1,53 @@ +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.g2d.BitmapFont.TextBounds; + +public class Msg extends Bg +{ + private BitmapFont font; + private String text; + private int padding; + private float x; + private float y; + private float duration; + private float elapsed; + private boolean visible; + + public Msg(BitmapFont font, TextureRegion region) + { + super(region); + this.font = font; + } + + public void write(String text, float x, float y, float duration, int padding) + { + this.text = text; + this.x = x; + this.y = y; + this.duration = duration; + this.padding = padding; + this.visible = true; + this.elapsed = 0f; + TextBounds b = font.getBounds(text); + set(x, y, (b.width + (padding * 2)), (b.height + (padding * 2))); + } + + public void animate(float delta) + { + if (!visible) return; + elapsed += delta; + if (elapsed >= duration) + visible = false; + } + + @Override + public void draw(Batch batch) + { + if (!visible) return; + super.draw(batch); + font.draw(batch, text, (x + padding), (rect.y + rect.height - padding)); + } +} |