6.8.6. Method updatePositions

Method updatePositions (Fig. 6.12) is called by the CannonThread’s run method (Section 6.8.14) to update the on-screen elements’ positions and to perform simple collision detection. The new locations of the game elements are calculated based on the elapsed time in milliseconds between the previous and current animation frames. This enables the game to update the amount by which each game element moves based on the device’s refresh rate. We discuss this in more detail when we cover game loops in Section 6.8.14.

209    // called repeatedly by the CannonThread to update game elements210    private void updatePositions(double elapsedTimeMS)211    {212      double interval = elapsedTimeMS ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.