package nl.joozey.games.asmallworld;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

/**
 * Created by mint on 24-4-17.
 */

public class SpriteTextWriter {

    private Texture numberTex;

    private Sprite[] numberSprites;

    private float x, y;

    public SpriteTextWriter(String text, float x, float y) {
        numberTex = new Texture("numbers.png");

        setText(text, x, y);
    }

    public void dispose() {
        numberTex.dispose();
    }

    public void setText(String text, float x, float y) {
        numberSprites = new Sprite[text.length()];

        this.x = x;
        this.y = y;

        int i = 0;
        for (char c : text.toCharArray()) {
            TextureRegion textureRegion = new TextureRegion(numberTex, (c - '0') * 15, 0, 15, 23);
            numberSprites[i] = new Sprite(textureRegion);
            numberSprites[i].setPosition(x + 15 * i, y);
            i++;
        }
    }

    public void draw(SpriteBatch batch) {
        for (Sprite sprite : numberSprites) {
            sprite.draw(batch);
        }
    }

}
