summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject/Hud.java
blob: b1cf5eabd03177488371880c515a7fde33b890e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ch.asynk.zproject;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Disposable;

public class Hud implements Disposable
{
    private final Sprite hud;
    private final GlyphLayout glyphLayout;
    private final BitmapFont font20;
    private final BitmapFont font25;

    public Hud(final Assets assets)
    {
        this.hud = new Sprite(assets.getTexture(assets.CORNER));
        this.glyphLayout = new GlyphLayout();
        font20 = assets.getFont(assets.FONT_20);
        font25 = assets.getFont(assets.FONT_25);
    }

    @Override public void dispose()
    {
        hud.getTexture().dispose();
    }

    public void draw(Batch batch, final Rectangle rect)
    {
        float right = rect.x + rect.width - hud.getWidth();
        float top = rect.y + rect.height - hud.getHeight();
        hud.setRotation(0);
        hud.setPosition(rect.x, top);
        hud.draw(batch);
        hud.setRotation(90);
        hud.setPosition(rect.x, rect.y);
        hud.draw(batch);
        hud.setRotation(180);
        hud.setPosition(right, rect.y);
        hud.draw(batch);
        hud.setPosition(right, top);
        hud.setRotation(270);
        hud.draw(batch);
        glyphLayout.setText(font20, "Hello");
        font20.draw(batch, glyphLayout, 60, 30);
        glyphLayout.setText(font25, "worlD");
        font25.draw(batch, glyphLayout, 120, 32);
    }
}