Game Development Reference
In-Depth Information
play and logic variables and fire off events to Main.as to change state if necessary. All of these
functions will be discussed in detail next.
Defining the update function
The update function is called every frame tick during the by the Super Click runGame function (as
discussed in the previous section). Its duties are to create new circles, update the size of the
circles currently on the screen, and remove any circle that has reached its maximum size. It also
handles updating the ScoreTextField instances and removes them if they have been on screen
passed their frame tick life values.
private function update():void {
if (circles.length < maxCirclesOnscreen && numCreated <
numCircles) {
var newCircle:Circle;
if (int(Math.random() * 100) <= percentBadCircles ) {
newCircle=new Circle(Circle.CIRCLE_BAD)
}else {
newCircle=new Circle(Circle.CIRCLE_GOOD)
numCreated ++;
}
addChild(newCircle);
circles.push(newCircle);
}
// Checks circles every frame for size and adds
//to their nextScale property
// if nextScale is larger than the max, removes the circle
var circleLength:int = circles.length-1;
for (var counter:int = circleLength; counter >= 0; counter--) {
tempCircle = circles[counter];
tempCircle.update(circleGrowSpeed);
if (tempCircle.nextScale > circleMaxSize ||
tempCircle.alpha <0 ) {
removeCircle(counter);
}
}
var scoreTextLength:int = scoreTexts.length-1;
for (counter= scoreTextLength; counter >= 0; counter--) {
tempScoreText = scoreTexts[counter];
if (tempScoreText.update()){ //returns true is life is over
removeScoreText(counter);
}
}
}
Search WWH ::




Custom Search