30 Sep

Get your blits out for the lads

30. September 2011 by Alex Stanbury

zelda At the moment, I’m working on a Flash platform game in my spare time. This has given me the opportunity to experiment with some of the clever techniques employed by game makers of years-gone-by in order to squeeze every last bit of performance out of their game engines. One of these techniques is called blitting which is used to decrease load on the processor and therefore increase the frame rate of the game.

mario Usually in Flash you would create Movieclips or Sprites for all your game objects and add them all to the display list when needed, moving them around using their x and y properties and so on. With blitting you do not use the display list for everything, rather you only have one Bitmapdata object added to the display list, commonly referred to as the canvas. The idea is to update the pixels of the canvas with the pixels of whatever it is you want to be displayed in your game. This method is much faster because the overhead of creating complex objects is avoided as you are working solely at the pixel level.

spritesheet You can see a simple example of using blitting here - From looking at the code you can see that the Box is being drawn into the canvas at a different position on every frame, in this case the box will move diagonally down the screen. This is a very simplified version of the method I have implemented in my game but you should be able to see how it works and the benefits this technique provides. You’ll notice that I have only added a few properties to the Box object - If I was using a Sprite or MovieClip then I would also be adding a lot more complexity which I wouldn’t necessarily make use of.

Of course you’d want to be using something more interesting than a pink box in your game unless you were making a game where the protagonist was in fact a pink box…but that would be a pretty shit game. One way of adding your own graphics is by using sprite sheets, another very common practice used when making games. You can read more about sprite sheets here.

With Adobe’s recent anouncement of the Starling Framework (an open-source Actionscript API for utilising the GPU directly) game development using Flash may not be so much about optimisation as it has been in the past but it’s still useful to know the techniques that many thousands of classic games such as Legend of Zelda and Super Mario World have used.

For more reading on this and other equally interesting subjects head over to 8-Bit Rocket where there are many well written and highly useful tutorials.

Also, there is an excellent 3 part video tutorial on gotoAndLearn.com that deals specifically with blitting and sprite sheets, well worth a watch!

What a load of blit.

Subscribe to newsletter:

RSS Feed



Archive: