diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-02 12:26:29 +0100 | 
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-02 12:26:29 +0100 | 
| commit | 207831991cbb92778b2cea586634d66a769bddfa (patch) | |
| tree | 4a39e7f1e25cabeb5b7512c81bc729de5ba2fbfc /core/src/ch | |
| parent | 98bfaf9b8db508fd76b5367ebeb37c648a685ee2 (diff) | |
| download | RustAndDust-207831991cbb92778b2cea586634d66a769bddfa.zip RustAndDust-207831991cbb92778b2cea586634d66a769bddfa.tar.gz | |
add game/hud/Text
Diffstat (limited to 'core/src/ch')
| -rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Text.java | 66 | 
1 files changed, 66 insertions, 0 deletions
| diff --git a/core/src/ch/asynk/tankontank/game/hud/Text.java b/core/src/ch/asynk/tankontank/game/hud/Text.java new file mode 100644 index 0000000..e468ccc --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/hud/Text.java @@ -0,0 +1,66 @@ +package ch.asynk.tankontank.game.hud; + +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +import ch.asynk.tankontank.engine.gfx.Drawable; + +public class Text implements Drawable, Disposable +{ +    public boolean visible; +    public float x; +    public float y; +    private float ry; +    private String text; +    private BitmapFont font; + +    public Text(BitmapFont font, String text) +    { +        this.font = font; +        this.text = text; +        this.visible = true; +    } + +    @Override +    public void dispose() +    { +        font.dispose(); +    } + +    public void setPosition(float x, float y) +    { +        TextBounds b = font.getBounds(text); +        this.x = x; +        this.y = y; +        this.ry = (y + b.height); +    } + +    public void write(String text) +    { +        this.text = text; +    } + +    public void write(String text, float x, float y) +    { +        this.text = text; +        setPosition(x, y); +    } + +    @Override +    public void draw(Batch batch) +    { +        if (!visible) return; +        font.draw(batch, text, x, ry); +    } + +    @Override +    public void drawDebug(ShapeRenderer shapes) +    { +        if (!visible) return; +        TextBounds b = font.getBounds(text); +        shapes.rect(x, y, b.width, b.height); +    } +} | 
