Creating a Simple Flash Game

So you want to impress your friends and get all the girls by creating your own game, do you? Well, read on, because I am going to show you how. This article assumes a few things, so let's get these out of the way right away.

  • You need to have some programming skills. This isn't a tutorial on coding.
  • Do not assume coding games is easy. It's not easy. That's why commerical games programmers get paid so well.
  • You want to learn new stuff, you have a brain and are not afraid to use it!
  • Unless you are a genius, even writing a simple game can take quite a while, so set aside a decent amount of time. Of course, it's also fun (most of the time).
  • It's not going to get you any girls.

Still here? Good stuff. OK so let's get started. Like a good book, your computer program is going to have a beginning, a middle and an end. The basic structure we use will look like this:

Load assets (sprites / sounds / backgrounds )
Splash screen
Read input (keyboard, mouse)
Move sprites
Collision detection
Clear screen
Draw playfield
Draw sprites
Wait for vertical blank
Until end of game
Game over screen

The step labelled as wait for vertical blank could probably do with some explanation. Computer monitors refresh at a specified rate (usually ranging from 50Hz to 85Hz), meaning the screen is updated 50 to 85 times a second. If you can redraw your screen at that rate, then you, my friend, are going to achieve the ultimate in smoothness. This also serves to regulate the speed your game runs at.

Commonly a technique known as double-buffering is used during this process. The reason we use double-buffering is quite simple; you can't redraw the game screen while the player is looking at it. Using double-buffering, we have two screens (or buffers), A and B. While the user to watching buffer A we can draw onto buffer B. At the vertical blank, we switch the process, the display is switched to buffer B, and we start drawing onto buffer A. This process is repeated every refresh cycle. Most APIs have an instruction such as setBuffer to start drawing into a different buffer. This way we can draw secretly into the hidden buffer all kinds of complicated graphics and it can't be seen by the user until it's flipped instantly into view.

This tutorial is going to be in Flash, so you won't have to think about double-buffering, because it's done internally by the Flash runtime environment. You also don't have to worry about your online game running at 85fps, because you'd need some kind of super computer to achieve that kind of speed in Flash! It's OK though, because 30fps is good enough for our purposes.



Next we are going to discuss game design and gameplay


( categories: )