Reader small image

You're reading from  Android Programming with Kotlin for Beginners

Product typeBook
Published inApr 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789615401
Edition1st Edition
Languages
Right arrow
Author (1)
John Horton
John Horton
author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton

Right arrow

The game loop


So, what is a game loop anyway? Almost every live drawing, graphics-based app, and game has a game loop. Even games that you might not expect, such as turn-based games, still need to synchronize player input with drawing and AI, while following the rules of the underlying OS.

There is a constant need to update the objects in the app, such as by moving them and drawing everything in its current position while simultaneously responding to user input:

Our game loop comprises three main phases:

  1. Update all game and drawing objects by moving them, detecting collisions, and processing the AI, such as particle movements and state changes

  2. Based on the data that has just been updated, draw the frame of animation in its latest state

  3. Respond to screen touches from the user

We already have a draw function for handling this part of the loop. This suggests that we will have a function to do all the updating as well. We will soon code the outline of an update function. In addition, we know that...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Android Programming with Kotlin for Beginners
Published in: Apr 2019Publisher: PacktISBN-13: 9781789615401

Author (1)

author image
John Horton

John Horton is a programming and gaming enthusiast based in the UK. He has a passion for writing apps, games, books, and blog articles. He is the founder of Game Code School.
Read more about John Horton