View Full Version : Showing a Score
PledgeDuster
January 29th, 2009, 06:00 PM
I recently read through and created the vertical shooter from Bruno's tutorial. (which might i say was extremely good) and i noticed in the action script that there was a score function.
I was wondering if anybody knew a way of showing the score within the game?
Thanks for your time :)
Exodar
February 1st, 2009, 08:29 PM
Alright, I took a look at the tutorial and didn't see the score function you mentioned anywhere. In the following section of the code however, you can see that there is a score variable being updated:
function initDragons() {
for (i; i<dragons; i++) {
attachMovie("dragon", "dragon"+i, i);
dragon = _root["dragon"+i];
updateDragons(dragon);
dragon.onEnterFrame = function() {
if (this.hitTest(arrows)) {
score += 5;
trace(score);
arrowActive = false;
removeMovieClip(arrows);
updateDragons(this);
}
if (this._x>0) {
this._x -= this.velo;
} else {
updateDragons(this);
}
};
}
}
So to answer your question if you wanted to have the score shown within the game, here's what you can do:
1. Create a dynamic text field on the stage which will display the score
2. Give it an instance name, for ex. scoreText
3. Add the following code to the initDragons function above (right after the part in bold):
scoreText.text = score
Hope this helps
JapanMan
February 2nd, 2009, 11:42 AM
Alternatively, you can just give the dynamic text box a Variable name of "score"; no other code is needed, then. The "scoreText.text = score" is too much typing for me, so I do it this way ;)
neilmmm
February 2nd, 2009, 04:17 PM
it is better practice to use instance name than the var
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.