En essayant d'avoir une image-objet 2-d, descendante qui tourne et est animée, j'ai la classe principale où elle est rendue, et une classe 'assets' distincte où elle est créée. La rotation fonctionne, mais l'image-objet reste sur le même cadre. J'ai utilisé le wiki libgdx pour essayer d'animer mon sprite https://github.com/libgdx/libgdx/wiki/2D-AnimationAnimation de sprites Libgdx Java
Voici le code dans la classe d'actifs:
public class Asset implements ApplicationListener, Screen{
public static Texture walkSheet;
private static final int FRAME_COLS = 4;
private static final int FRAME_ROWS = 2;
static Animation walkAnimation;
static TextureRegion[] walkFrames;
static TextureRegion currentFrame;
static SpriteBatch spriteBatch;
static float stateTime;
public static void load(){
walkSheet = new Texture(Gdx.files.internal(".png"));
TextureRegion[][] tmp = TextureRegion.split(walkSheet, walkSheet.getWidth()/FRAME_COLS, walkSheet.getHeight()/FRAME_ROWS); // #10
walkFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS];
int index = 0;
for (int i = 0; i < FRAME_ROWS; i++) {
for (int j = 0; j < FRAME_COLS; j++) {
walkFrames[index++] = tmp[i][j];
}
}
walkAnimation = new Animation(0.1f, walkFrames); // #11
spriteBatch = new SpriteBatch(); // #12
stateTime = 0f;
stateTime += Gdx.graphics.getDeltaTime();
currentFrame = walkAnimation.getKeyFrame(stateTime, true);
}
Et voici comment il est rendu:
game.batch.draw(Asset.currentFrame, x, y, (float)85, (float)85, (float)170, (float)170, (float)1, (float)1, (float)angleDegrees + 270);
Que dois-je besoin de faire pour animer correctement l'image-objet?
l'image de http://www.reinerstilesets.de/ –