Game Development Reference
In-Depth Information
private function cleanUp():void {
var circleLength:int = circles.length-1;
for (var counter:int = circleLength; counter >= 0; counter--){
removeCircle(counter);
}
var scoreTextLength:int = scoreTexts.length-1;
for (counter= scoreTextLength; counter >= 0; counter--) {
removeScoreText(counter);
}
}
} // close class
} // close package
Using the same loop optimizations you have seen a few times in this chapter, the cleanUp
function calls the removeCircle function for each Circle instance left in the circles array.
As with the final function on all of our classes, the final two closing brackets ( } ) close the class
and the package respectively.
That's it for the SuperClick game class. Now let's move on to the two final classes for this game.
First up is the Circle.as class.
The Circle Class
The Circle class dynamically creates a circle shape. It extends the Sprite class, so it is
clickable using the MouseEvent.CLICK event.
Defining the Circle class
These are the static constants needed for the Circle class: CIRCLE_GOOD and CIRCLE_BAD .
The following public attributes are needed:
clicked : This Boolean is set to true when the circle is clicked.
type : This integer holds one of the two static constants: CIRCLE_GOOD or CIRCLE_BAD . This
could have simply be a Boolean using true for good and false for bad, but to make the
attribute more extensible in the future, we have used constants to define the basic types.
For example, later you might want to add a CIRCLE_POWER_UP constant that gives the
player extra time.
nextScale : This attribute holds the next scaleX and scaleY value for the Circle . It is
updated in the internal update function that is called by the SuperClick.update function
and is rendered in the render function of the SuperClick class.
fadingOut : This Boolean value set to true once a CIRCLE_GOOD is clicked by the player.
For the constructor arguments, we need a passed-in type value that will be one of the two
constants: CIRCLE_GOOD or CIRCLE_BAD .
Search WWH ::




Custom Search