Game Development Reference
In-Depth Information
Creating the Circle class in the package structure
As with all of
Main.as
and the
SuperClick.as
class files, the
Circle.as
class file will reside in the
game specific package structure.
This is the Flash IDE folder structure:
/source/projects/superclick/flashIDE/com/efg/games/superclick/Circle.as
And this is the structure for the Flex SDK (using Flash Develop):
/source/projects/superclick/flexSDK/src/com/efg/games/superclick/Circle.as
Importing the classes and declaring variables for Circle.as
The properties needed for a new
Circle
are a
type
variable to hold the
CIRCLE_GOOD
or
CIRCLE_BAD
constant, a
clicked
variable that is set to
false
, a
fadingOut
variable set to
false
,
and a
nextScale
property that will be updated in the
Game.update
function.
The Boolean
clicked
used in the collision detection portion of the game logic. If a
Circle
is clicked,
this property is set to
true
and evaluated in a loop inside the game's
checkCollisions
function.
package com.efg.games.superclick
{
// Import necessary classes from the flash libraries
import flash.display.Shape;
import flash.display.Sprite
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
/**
* ...
* @author Jeff Fulton
*/
public class Circle extends Sprite {
//Constsants used to define circle type
public static const CIRCLE_GOOD:int = 0;
public static const CIRCLE_BAD:int = 1;
public var type:int;
public var clicked:Boolean=false;
public var fadingOut:Boolean = false;
public var nextScale:Number;
The
nextScale
variable is the first “update” variable you have seen. We could simply set the scale
of the
circles
in the update function by applying the new
scale
value to the
circle.scaleX
and
scaleY
attributes directly. We have added a step to this process by actually updating a
nextScale
variable in the update portion of the game and then applying the
nextScale
to the
circle.scaleX
and
circle.scaleY
in the render portion of the game. Although there is no real need for this
separation in Super Click, it is a good habit to get started with. As we progress through the games
in this topic, you will see this type of separation more often, and in some games, separate
update
and
render
functions will be applied to improve game performance. That's getting a little ahead of
ourselves though. For now, it makes for good code organization and functions that don't attempt
to do too many tasks.