views:

271

answers:

2

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
}
A: 

Could we see more of the code? What size are your chess piece icons? You might consider reducing their quality in order to reduce draw time. You could also limit the number of icons that you're loading (load one of each type for each color), and then have a matrix store what type of icon to load for each square.

Adam
+1  A: 

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.

fhucho