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

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

public class FramedSprite
{
    public Texture texture;
    public TextureRegion[] frames;
    public final int width;
    public final int height;
    public final int cols;
    public final int rows;

    public FramedSprite(Texture texture, int cols, int rows)
    {
        this.cols = cols;
        this.rows = rows;
        this.width = (texture.getWidth() / cols);
        this.height = (texture.getHeight() / rows);
        this.texture = texture;
        TextureRegion[][] tmp = TextureRegion.split(texture, width, height);
        frames = new TextureRegion[cols * rows];
        int idx = 0;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                frames[idx++] = tmp[i][j];
            }
        }
    }
}