Search code examples
javaandroidopengl-eschesssurfaceview

Should I use OpenGL for chess with animations?


At the moment I am experimenting with SurfaceView for my chess game with animations. I am getting only about 8 FPS in the emulator. I draw a chess board and 32 chess pieces and rotate everything (to see how smooth it is), I am using antialiasing. On the Droid I'm getting about 20FPS, so it's not very smooth. Is it possible to implement a game with very scarce and simple animations without having to use OpenGL?

This is what I do every frame:

// scale and rotate
matrix.setScale(scale, scale);
rotation += 3;
matrix.postRotate(rotation, 152, 152);

canvas = surfaceHolder.lockCanvas();
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG));
canvas.setMatrix(matrix);

canvas.drawARGB(255, 255, 255, 255); // fill the canvas with white
for (int i = 0; i < sprites.size(); i++) {
    sprites.get(i).draw(canvas); // draws chessboard and chess pieces
}

Solution

  • I decided to prescale all the bitmaps when the SurfaceView is created. Now I don't need to use the transformation matrix at all. I'm getting over 30 FPS on emulator and on actual device (Droid) it's completely smooth. I also removed canvas.drawARGB(255, 255, 255, 255); which increased the FPS by about 5.