Game Development Reference
In-Depth Information
Framework classes beyond Main
The framework does not rely on
FrameWorkStates
and the
GameFrameWork
classes alone. We are
now going to define and explain the classes that make up the
BasicScreen
(and its helper
classes),
ScoreBoard
, and the custom event classes. We have discussed all each of these briefly
in the
GameFrameWork.as
class description. Now, we take a look at each in greater detail.
The BasicScreen class
All of the simple screens in this basic game framework are created using a very simplified
BasicScreen
class. The
BasicScreen
class can become a parent class for more elaborate
screens, but in the basic framework, it is very simple. Each screen contains some text positioned
on the screen, an OK button if needed and a background color. That is all. If the OK button is
needed, there is an event inside the
BasicScreen
class that is fired off, and it, in turn, fires off its
own event to tell
GameFrameWork
class that it has been clicked. This makes use of a custom event
class instance (
okButtonClickListener
) that we will create in the next section.
You should save this class file in the folder structure we created earlier in the chapter to
correspond to the framework package.
/source/classes/com/efg/framework/BasicScreen.as
Here is entire code listing for this class.
package com.efg.framework
{
// Import necessary classes from the flash library
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextFormatAlign;
/**
* ...
* @author Jeff Fulton, Steve Fulton
*/
public class BasicScreen extends Sprite {
private var displayText:TextField = new TextField();
private var backgroundBitmapData:BitmapData;
private var backgroundBitmap:Bitmap;
private var okButton:SimpleBlitButton;
//ID is passed into the constructor. When the OK button is
//clicked,a custom event sends this id back to Main
private var id:int;