O'Reilly logo

Android 3.0 Animations by Alex Shaw

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

Time for action—creating smooth game loops

We are going to liberate our animation from the constraints of frame-by-frame updating. We will keep the notion that there are fixed, logical frames, but we will update the calculateDisplay portion of the code to update only a fraction of a frame at once.

Keeping the idea of fixed logical frames is not necessary, but we need some way of keeping the pace of the animation constant, and it shows the link between this animation and the previous one.

  1. Firstly, we are going to update the game loop. Open up BubblesView.java.

    Navigate to the run method in the GameLoop class and replace it with the following:

    public void run() { Canvas canvas = null; long thisFrameTime; long lastFrameTime = System.currentTimeMillis(); ...

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