summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/FramedSprite.java
blob: 33a6eb215c96240bdb2dfd99391621412f4018a1 (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
53
package ch.asynk.gdx.boardgame;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class FramedSprite implements Drawable
{
    private TextureRegion[][] frames;
    private TextureRegion frame;
    public final int rows;
    public final int cols;
    public float x;
    public float y;
    public float a;

    public FramedSprite(Texture texture, int rows, int cols)
    {
        this.frames = TextureRegion.split(texture, (texture.getWidth() / cols), (texture.getHeight() / rows));
        this.frame = frames[0][0];
        this.rows = rows;
        this.cols = cols;
        this.x = 0;
        this.y = 0;
        this.a = 0;
    }

    public FramedSprite(FramedSprite other)
    {
        this.frames = other.frames;
        this.frame = other.frame;
        this.rows = other.rows;
        this.cols = other.cols;
        this.x = other.x;
        this.y = other.y;
        this.a = other.a;
    }

    public void setFrame(int row, int col)
    {
        this.frame = frames[row][col];
    }

    public TextureRegion getFrame()
    {
        return frame;
    }

    @Override public void draw(Batch batch)
    {
        batch.draw(frame, x, y, 0, 0, frame.getRegionWidth(), frame.getRegionHeight(), 1f, 1f, a);
    }
}