Jan Dragsbaek
Jan Dragsbaek

Reputation: 8101

Android canvas redraw with 30fps

Im currently trying to implement the simple bouncing ball (in 2d) on my android device (physics based on device rotation and multiple balls coming in at a later point).

I have created a CustomDrawView class that extends View with a onDraw function that draws a circle in the centre of the screen. The math to get it moving correctly around is irrelevent, as my question is where i should call invalidate on the CustomDrawView.

Ofcourse battery is a important factor aswell, which method is best for saving battery?

Upvotes: 2

Views: 1215

Answers (1)

TurqMage
TurqMage

Reputation: 3321

From what I have seen with Android views they aren't the best if you are planning on making anything with framerate is very important. They snowball very quickly and the message passing pipeline used draw them is often the slowest thing your program will do that frame. I would just move the rendering now into OpenGL. Using the SurfaceView you can still get setup very quickly (ok SurfaceView also isn't great but much better than all Views).

If I were to use views, I would use your first method and setup a timing thread, use it sort of a like a standard Game loop that executes an update then triggers a draw then waits to ensure a full 1/30th of a second has passed and loops.

Upvotes: 2

Related Questions