Let’s Talk Basics

Hey guys Nemo is back from finishing UNI! So I’ve been planning out what content Game related topics to talk to with you guys, and decided to start from the ground up on game programming algorithms and techniques!

The topics that I’ll be covering over time:
1. The basics – Game Loops, Objects
2. 2D Graphics – Sprites, Tiles
3. Algebra – Vectors, Matrices
4. 3D Graphics
5. Input
6. Sound
7. Physics
8. Camera
9. AI
10. UI
11. Languages
12. Networking Games

Yes, I have a lot of content to cover with you guys!

Note: I am not a qualified tutor nor am I trying to be one. I am still a learning and pursuing in the field of game development. Content that I put up are purely on my understanding and experience from game development. I am just a fellow blogger that wishes to spread the joy of game development. So then with that said. Shall we

Let’s Talk Basics!


Basically, a game program is one big loop, a loop repeats a series of actions until the player has terminated the game. We call this term as the Game Loop, which can also be referred to as a frame. Yup that’s the same frame when hear gamers talk about their fps “Oh man I have 300 FPS (frames per second) my computer is so badass”. 300 FPS would mean that the Game Loop is completing 300 loops per second. The Game Loop contains everything that occurs in the game, such as processing the input, updating the game world and also generating outputs (2D or 3D graphics, audio, music and dialogue). Whatever is in the game is in the Game Loop.

The Game Loop put into Pseudo-code:

while game active
process input
update game world
generate output

Note: This is the very basics of a game loop architecture for simple games. Not all games use this game loop, instead they would use Multithreaded Game Loops.

Multithreaded Game Loops are programmed to harness the full potential of the computers CPU and it’s available cores. So that it can execute multiple lines of code at the same time thus reducing the heavy load, and giving the players a steady 60 FPS on their game. However there are some drawbacks to using multithreaded game loops in some occasions, due to its split processing there can be delays, which could cause input lag. Input lag refers to when a player inputs and the game displays the character moving a fraction slower. This tiny lag can be detrimental for games that relies on precision, timing and relexes such as Fighting Games. Other than that, multithreaded is the way to go for any game that requires heavy load of processing.

Time and Space

“Time waits for no one”

Games rely on time, without time there wouldn’t be any motion or action in the game. Before we get into talking about time, we need to understand the clear difference between Game time & Real Time. This might sound obvious but Game time is the time elapsed in the game’s world, whereas real time is the time elapsed in the real world. What I mean by this is, Game time can be programmed to fit the need of the game, time can run slower or faster. Whereas Real time is constant, runs at the same pace all day everyday of our lives.

Now then, lets rewind the time a bit, when games first game out, they were programmed to be played specific processor speeds. However as time and technology grew, more variations and faster processors came in the market. Which meant that games designed to be played on specific processors weren’t playable on newer processors as the game would run 10 times faster than usual because the game is being processed at a faster rate. We’ve probably have seen this once in our lives, when we put in an old dos games into our new computers with intel i7 processor and when we ran it, it would run super fast making it impossible to play, causing us to download a program to lower our processing speed to match the game.

This problem has been solved by the use of Delta Time!
Delta Time
– The time in seconds it took to complete the last frame.
So what does delta time actually mean?, well instead of thinking movement in terms of pixels per frame, we put it in terms of pixels per second. Regardless of the frame rate, any object using delta time will move exactly the same over the same period of time.

The Delta Time put into Pseudo-code:

object.position.x += 120 * deltaTime

The object will move 4 pixels per frame when the game is running at 30 FPS, whereas it will move 2 pixels per frame at 60 FPS. They would both be moving the same amount however the higher FPS would have a smoother transition.

Note: Any transformation, rotation and scaling should be done using the function of Delta Time.

So how is delta Time calculated exactly?
Delta Time is dependent on the elapsed time of real time since the previous frame.

while game active
realDeltaTime = time since last frame
gameDeltaTime = realDeltaTime * gameTimeFactor
process input (done using gameDeltaTime)
update game world
generate output

Game Objects

Games consist of Game Objects. Game Objects by definition are everything that are required in the game. They can categorized into three types of Game Objects:

Non-Static Objects
These objects can be your main protagonist/antagonist or any moving objects in the game that are required to be updated each frame. These occur in the “generate output” in the main Game Loop.

Static Objects
These objects are your background, UI frames that don’t move and do not require to be updated. They only have to be drawn once.

Trigger Objects
Triggers are updated every frame however do not require to be drawn. A clear example of this is the camera within the game. Triggers also control the flow of the game, it determines when it spawns other objects into the game.

Well that concludes the first content chuck. I hope you guys got the basics of a game program. Ciao for now!


One thought on “Let’s Talk Basics

  1. […] using Unity3D was the sheer amount of chaos it can produce. Unity handles the main game loop logic(mentioned previously here) for you behind the scenes which can have nasty side-effect; It becomes extremely difficult trying […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s