From 76f7f3d377279d3d2a72cf5985e028e2a6cfdf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 15 Oct 2014 17:24:34 +0200 Subject: add Hud/Msg --- core/src/ch/asynk/tankontank/game/hud/Msg.java | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/game/hud/Msg.java 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)); + } +} -- cgit v1.1-2-g2b99