Part 1 of 4:
Preliminaries and Translation

Introduction

So you have this great idea for a game. It could be an RPG top-down adventure, a side-scroller action, a puzzle game, or even something else! So get to planning and designing how your game will run and you come across the graphics area. You feel you need something more powerful than the simple scale() rotate() commands that effect only the pixel rendering of images but not their positional rendering in Blitzmax, but you become stuck. You have world scaling and rotation working in most cases, but you’re codes a mess and it isn’t elegant and easy to maintain and has just become ‘throw-away’ code just to get this game done. You don’t fully understand why some of it is working and why other parts fail to render correctly when you change a seemingly insignificant setting…like setting origins.

I’m sure that paints a pretty accurate picture for many beginning game developers and I’m sure we’ve all been there in some form or another. I know I’ve been there several times myself. At about the 3rd or 4th time I came across this issue I decided it was time to write a simple 2D camera library so I can just be done with it. It later evolved into a little more sophisticated 2D drawing framework, which allowed asset management, layering, and easy animation loading, but that’s beyond the scope of this tutorial.

This tutorial is designed to help you come to grips with doing transformations on your game world to allow for much more flexible gameplay and design. Why should you have to worry about complicated expressions to draw your images everytime you want to zoom into your level or rotate? With the added bonus of Blitzmax’s OOP style this can become a one time deal and then re-use this code easily and without worry everytime you want to add in this functionality :) . By the end of this tutorial series you will have a functional two dimensional camera class you can use in your games for easy zooming, rotating, and moving. In Tutorial 1 you will have a very basic camera that can move around in a 2D world and render your images with you having to worry about displacement or origins.

So lets move onto the basics…