Tuesday, September 27, 2011

AS2: Score System

Source code for this tutorial is available at: http://adf.ly/2vt0t

Welcome to Tutorial #3! In this tutorial I will teach you how to create your own customizable scoring system for your games.

Let's get started by opening up a new document in Actionscript 2.0
First, create your character movie clip. So draw a shape for your character a call it "character". The registration point does not entirely matter. Once you have a movie clip called "character", give it an instance name "char". Don't forget to give the character it's movement actions! If you need the code to move the character, go here: http://ciretutorials.blogspot.com/2011/09/as2-arrow-keywasd-movement.html















*Hint: You can give instance names through the properties panel.


There are many different ways to utilize a scoring system. In this tutorial I will show you how to collect coins to increase your score. So create an instance of a coin on the stage. Convert it to a movie clip, and call it "coin". Once again, registration point does not matter. You do not need to give the coin an instance name. You can now make duplicates of the coin anywhere you want on the stage.

Next, go into the coin movie clip. Select the shape inside the movie clip and convert it to another movie clip called "coin_child".









Once you have created the child movie clip inside of the parent coin movie clip, open up the coin_child's actions and type:

onClipEvent(enterFrame){
if(_root.char.hitTest(this._parent)){
unloadMovie(this._parent);
_root.score+=1;
}
}

unloadMovie(this._parent) means, if the character hits the coin, then delete the movie clip.

Now we just need to set up the score textbox that lets the player know what their score is. Simply create
a new dynamic textbox on the stage, and give it a variable name of "score".































*Hint: While Instance Names deal with movie clips and text in textboxes, Variable Names are used to deal with numbers such as score, health, distance etc.

Finally, the last piece of code you need, goes in the main timeline frame:
score=0;
This sets the score to be 0 at the beginning of the game.














Well, that concludes Tutorial #3 on Scoring Systems! Hope this helped! Thanks for viewing

Source code is available here: http://adf.ly/2vt0t

3 comments: