Game Development Reference
In-Depth Information
multiplier would simply be 1 , and after the circle starts to increase in size greater than 1 , the score
for the click will be less than the maximum. For example, if the scaleX of the circle is 2 , then half
of the value, or .5 , will be passed in as the score multiplier.
Note that unlike in AS2, AS3 display objects do not use 0 to 100 scales for with the scaleX ,
scaleY , or alpha attributes. In AS3, the scale is 0 to 1 for these attributes: 1 represents that same
value as 100 did in AS2. This may confusing at first, but once you get the hang of it, it is quite
easy to remember.
Fading out the circle
We don't remove the Circle instance from the screen right as it is clicked. We first want to fade
out the Circle before it is removed from the screen. We do this by setting the
tempCircle.fadingOut variable to true . When a Circle instance is first detected to be clicked,
this fadingOut variable will be false . We will need to set it to true :
if (tempCircle.clicked && ! tempCircle.fadingOutCircle) {
tempCircle.fadingOut=true.
When the alpha value of the Circle is still 1 (the maximum), we know that it has not started to
fade out yet. We then set the fadingOut attribute of the Circle instance to true , add to our score ,
and create the ScoreTextField instance to display on the screen. We then want to check if the
Circle is good ( CIRCLE_GOOD ) and if the alpha value is still set to 1 . This means we have not yet
processed it as a clicked circle:
if (tempCircle.type==Circle.CIRCLE_GOOD && tempCircle.alpha==1) {
var scoreAdd:int=maxScore * scoreAdjust;
addToScore(scoreAdd);
tempScoreText = new ScoreTextField(String(scoreAdd), textFormat,
tempCircle.x,tempCircle.y, 20);
scoreTexts.push(tempScoreText);
addChild(tempScoreText);
We create a new ScoreTextField instance by passing in the score value we calculated for the
clicked Circle along with our precreated TextFormat object instance, the x and y values to place
the ScoreTextField , and the life ( 20 ) in frames for the ScoreTextField to remain on the screen.
With the fadingOut attribute set to true , the update function in the Circle instance will start to
decrement the alpha attribute of the Circle instance rather than increase its size. When the
alpha value reaches 0 , it will be removed from the screen.
Defining the addToScore function
The addToScore function is called by the checkCollisions function when a good (blue) circle has
been clicked. It takes a single parameter, a multiplier for the maxScore variable. The value
1/scaleX of the clicked circle is passed. This allows the score received for the click to be based
on the size of the Circle instance. The smaller the circle, the more points the player will earn for
clicking it. ScoreBoard custom events are fired off to update display fields for score, clicked, and
percentAchieved .
Search WWH ::




Custom Search