I'm creating a basic endless runner game on Android using SurfaceView.
I have background that recreates itself constantly, which was simple enough.
One problem I've always had is getting my head around animating sprite-sheets, not just in Android but other platforms as well.
Based on the problem I'm stuck on right now.. I have a sprite sheet thats 9 images 2 rows, 5 columns, with an empty space at the end of the second row. All of which is one single running animation.
I've made a Sprite Class.
public class Sprite {
GameView gameView;
Bitmap bmp;
private int x, y, width, height;
private int spriteColumns 5, spriteRows= 2;
private int currentAnim = 1;
public Sprite(GameView gameView, Bitmap bmp) {
this.gameView = gameView;
this.bmp = bmp;
this.width = bmp.getWidth() / spriteColumns;
this.height = bmp.getHeight() / spriteRows;
}
public void update() {
// do something here with currentAnim, x and y;
}
public void onDraw(Canvas c) {
update();
canvas.drawBitmap(bmp, x, y, null);
}
}
How do I go about doing this? Am I on the right track so far?