O'Reilly logo

Mastering Android Game Development by Raul Portales

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a frames-per-second (fps) counter

We have updated the DrawThread to run at an arbitrary number of frames per second, adapting to the time required to render instead of a fixed 30 fps, and we are using sprites. Now is the perfect time to add a frames-per-second counter. It is a very easy tool and is also handy to check performance.

We could have used a TextView, but there are some good reasons to draw it on the Canvas directly instead:

  • The performance of SurfaceView suffers when we overlay other views on top of it
  • It is an interesting example of other methods of drawing on the Canvas
  • We can remove and add it without touching the layout

We will make a class named FPSCounter that extends from GameObject and looks like this:

public class FPSCounter ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required