Skip to content
Thomas Cashman edited this page Aug 16, 2013 · 4 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 is 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.

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.

Dependency Injection

Dependency Injection is often used in enterprise applications via frameworks such as Spring or Guice. However it solves a problem often encountered in video game development:

"Where and when should I connect my components together?"

In mini2Dx you can place annotations on your objects to define how they are connected to each other and set up all the connections using the GameContext class. This is also useful for swapping component implementations for different platforms. This is further explained in the Dependency Injection Tutorial.

Clone this wiki locally