Skip to content
Thomas Cashman edited this page Aug 10, 2015 · 6 revisions

Mini2Dx was inspired by the Slick game development library and uses some concepts similarly. In this article we'll explore the concepts mini2Dx uses.

Basic updating and rendering

All games require logic to update characters, music, etc. before they are rendered on screen. However, rendering doesn't occur at a constant rate. mini2Dx attempts to render at 60 frames per second (FPS) but in reality, due to hardware and how OpenGL works, games will be rendered between 59 and 64 FPS.

Our game logic must perform animations, calculations, etc. at a constant rate regardless of the FPS but characters must render at their correct position at the time render is called. This is achieved through interpolation. Consider the following diagram:

--------------------------------------> TIME
-    -    -    -    -    - -  -    -    UPDATE
   -    -   -   -   -   -    -    -     RENDER

If render occurs between halfway between updates and a character at 0,0 is moving 4 pixels horizontally between updates, then when render is called the character should be rendered at 2,0. This is what interpolation achieves.

Note: It is also possible for multiple updates to occur before an interpolation and render call.

For more information on time steps and interpolation see the Fix your timestep article; mini2Dx is based on the last implementation.

The Game Loop

All games are essentially broken into 4 operations: initialise, update, interpolate and render. You'll see this implemented in our tutorials.

Initialise

This is run when the game starts and is only called once. Here you'll create any required objects and load any resources needed for your game. After the initialise method is finished, the update, interpolate and render methods are called continuously until the game ends.

Update

This is where your game will apply game logic, update animations, change background music, etc. The variable called 'delta' is provided and represents the amount of time in seconds to advance game logic. By default delta is 0.1 seconds.

Interpolate

This is where your game calculates the render coordinates of your sprites. The variable 'alpha' will be between 0.0 and 1.0, representing how much of an update to simulate, i.e. 0.5 means it is halfway through an update.

Render

This is where you'll draw you game to the screen.

Clone this wiki locally