Game Development Reference
In-Depth Information
movement logic. This allows for the game to appear to have free-flowing movement over a grid of
tiles, as the game characters will move a specified number of pixels each frame tick until the
center of the next time is reached. This system is a lot less limited than it seems, as it allows the
player to reverse the character's direction at any time, even before the next tile center has been
reached. We will not simply be playing an animation that shows the characters moving between
the tiles, which would not allow for user interaction before the player stopped on the next tile and
would make for an awkward game playing experience.
We will start by coding the movement of the main character on the level we created in Chapter 6.
If you have not completed Chapter 6, it might be a good idea to look it over and download the
final files from this topic's web site.
The BlitSprite Class
The current GameDemo.as reads in the tile sheet and level data and then displays the level on the
screen. There really isn't any game here yet, but it goes a long way toward getting us started.
What we need now is a way to place sprites on the screen and control their look with a tile sheet.
This class takes care of blitting from the tile sheet that represents the Sprite , allows tile sheet
animation, and contains attributes necessary for controlling basic movement.
We will create the class as part of the reusable framework that was started in Chapter 2. The
locations for the file in the framework will be as follows:
/source/classes/com/efg/framework/BlitSprite.as
Here is the complete code for the class:
package com.efg.framework
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.geom.Point;
import flash.geom.Rectangle;
/**
* ...
* @author Jeff Fulton
*/
public class BlitSprite extends Sprite {
private var bitmap:Bitmap;
public var bitmapData:BitmapData;
private var tileSheet:TileSheet;
private var rect:Rectangle;
private var point:Point;
public var animationDelay:int=3;
public var animationCount:int=0;
public var animationLoop:Boolean=false;
public var tileList:Array;
public var currentTile:int;
public var tileWidth:Number;
public var tileHeight:Number;
public var nextX:Number=0;
Search WWH ::




Custom Search