Slide 60
Slide 60 text
// EXPLOSION
protected static final int FRAME_COLS = 4;
protected static final int FRAME_ROWS = 4;
protected static final String EXPLOTION_SPRITE = "sprites/explosion/explosion1.png";
public void createExplosion() {
explosionSheet = new Texture(Gdx.files.internal(EXPLOTION_SPRITE));
TextureRegion[][] tmp = TextureRegion.split(explosionSheet,
explosionSheet.getWidth()/FRAME_COLS,
explosionSheet.getHeight()/FRAME_ROWS);
TextureRegion[] explosionFrames = 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++) {
explosionFrames[index++] = tmp[i][j];
}
}
explosionAnimation = new Animation(0.055f, explosionFrames);
}
public boolean drawExplosion(Batch batch, float posX, float posY, float width, float height) {
explosionTime += Gdx.graphics.getDeltaTime();
explosionCurrentFrame = explosionAnimation.getKeyFrame(explosionTime, true);
batch.draw(explosionCurrentFrame, posX, posY, width, height);
return (explosionTime > 0.45f);
}