Game Development Reference
In-Depth Information
2.
Next, if animationCount is greater than animationDelay , we will move to the next tile in
the tilelist array by updating the currentFrame property. If the car is going forward, we
will add 1 to the currentFrame property. If the car is going backward, we'll subtract 1.
3.
The animationDelay property will be set dynamically in the Game.as based on the
velocity of the car. The higher the value, the slower the wheels will appear to move.
We will see this code in the render function of the Game class.
4.
The loopCounter variable can be used to only animate through a set of frames for a
set amount of times. It is not used in this game.
Creating the Camera2D class
The Camera2D class doesn't look like much at first glance. It is little more than a structured set of
variables encapsulated into a class for convenience. It is how we use those variables in the game
that provides the power of the class. Currently, we are using it as a way to keep all of the
necessary variables for the camera in a single place for organization. You might find this to be an
odd way to organize code. That's OK; you can rip all of these variables out and put them directly
in your game class with very few changes. We have them separated because we assume in the
future that this will be a very nice base class for more elaborate child classes.
For old guys like us, this camera class would have been a perfect use of a struct in the C
language. In the 1990s, we created quite a few DOS games (mostly unreleased experiments
while in school and just starting out in programming). Most of our code ideas come from those
days (as you can tell). C is not an object-oriented language (though its cousin C++ is), The
struct was a way to create a sort of class by packaging up a series of variables together that
could be used as a unit. The Camera2D class is almost an exact duplicate of a struct Jeff used for
the same purpose in a scrolling Asteroids-like C game that he never finished. When looking for
things to write in this topic, we searched through some of our old code and came across it. It was
the inspiration for the game we will create in the next chapter.
The Camera2D class is located here:
/source/classes/com/efg/framework/Camera2D.as
And this is the code for the class:
package com.efg.framework
{
import flash.display.*;
import flash.geom.*;
/**
* ...
* @author Jeff Fulton
*/
public class Camera2D {
public var width:int;
public var height:int;
public var cols:int;
public var rows:int;
public var x:Number;
public var y:Number;
Search WWH ::




Custom Search