Game Development with raylib C++ — Day #3

Create a Game Loop and Game Class

Jean-Noel Seneque
4 min readOct 26, 2021


What makes games different from other applications is that the game must update many times a second for as long as the program runs. This is also known as the “Game Loop”.

The game repeats the following steps:

  1. Process any inputs
  2. Update the game world
  3. Generate any outputs

In this article, we are going to create a Game Class that will encapsulate the logic for this game loop. We are going to build on top of the last project that you can download from here. If you want to learn how to set up VSCode and raylib then go to this article.

Game class files

With the workspace open in VSCode (Visual Studio Code), click on the New file button and create a Game.h and Game.cpp files.

In the header file type the following code that defines the Game class.

Game header file

In the Game implementation file (cpp), let's start filling out the methods. We need to start with the constructor and deconstructor. At the moment, we will have them doing nothing as they still need a body.

In the Initialise method, we will move the setting the maximum frame rate and initialisation of the window here.

For the RunLoop method, we have three helper methods.

ProcessInput — gets any inputs from mouse, keyboards, gamepads, or any other inputs

UpdateGame — This is where we put all the processes for moving the player, pathfinding, collisions, determining which sprite to draw next, etc

GenerateOutput — This is where we put the code to draw sprites to the screen etc.



Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity