48 lines
1.4 KiB
Java
48 lines
1.4 KiB
Java
package utilidades;
|
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
|
|
|
public class Gifs {
|
|
private Texture textura;
|
|
private TextureRegion[] frames;
|
|
private int n_estados;
|
|
private float contadorEstado;
|
|
|
|
public Gifs(String ruta, int n_estados, int inicio_image, int desplazamiento,
|
|
int anchura, int x, int y, boolean flip) {
|
|
textura = new Texture(ruta);
|
|
this.n_estados = n_estados;
|
|
frames = new TextureRegion[n_estados];
|
|
for(int i = 0; i<n_estados; i++) {
|
|
frames[i] = new TextureRegion(textura, inicio_image+(i*desplazamiento)
|
|
, anchura, x, y);
|
|
frames[i].flip(flip, false);
|
|
}
|
|
}
|
|
|
|
public Gifs(Texture textura, int n_estados, int inicio_image, int desplazamiento,
|
|
int anchura, int x, int y) {
|
|
this.textura = textura;
|
|
this.n_estados = n_estados;
|
|
frames = new TextureRegion[n_estados];
|
|
for(int i = 0; i<n_estados; i++) {
|
|
frames[i] = new TextureRegion(textura, inicio_image+i*desplazamiento
|
|
, anchura, x, y);
|
|
}
|
|
}
|
|
public void avanzar(int speed, float delta) {
|
|
this.contadorEstado+=delta*speed;
|
|
if(this.contadorEstado > this.n_estados) {
|
|
this.contadorEstado=0;
|
|
}
|
|
}
|
|
public void draw(SpriteBatch batch, float x, float y) {
|
|
batch.draw(this.frames[(int)contadorEstado], x, y);
|
|
}
|
|
public void dispose() {
|
|
this.textura.dispose();
|
|
}
|
|
}
|