View Full Version : [AS2] help with scoring
DoubleUhy
02-12-2009, 10:12 PM
I'm new to Flash, and I've learned everything I know off of 2 tutorials. One was boring, and one was bad at explaining things. I tried combining what I learned to make a simple game, but it's not working well. What I want is to have the green ball move around, and collect coins for points, and die when the other circles hit it. But when the ball hits a coin, the coin disappears but the score doesn't update and the text even disappears. How can I fix it? Below is a link to the code.
http://rapidshare.com/files/197377187/Test.rar.html
Cauterize
02-13-2009, 11:37 AM
EDIT: Apologies, I wrote this as if i was coding in AS3. If you can convert it, then it should be fine
I havent opened up your file, but scoring should be fairly simple.
Set a variable for the score and the value of the coin
var score:Number = 0;
var coinValue:Number = 100;
On the code where the coin is removed, add the following
score += coinValue;
The reason I have set coinValue as apposed to putting +100, is that you can easily edit the value of the coin at the top of your code if needed, instead of searching through loads and loads of code.
Also, if you add other collectables in, you can use the same method as above and keep it neat and tidy.
Now, add onto the stage a Dynamic Text field and give it the instance name of scoreTxt.
add the following code
stage.addEventListener(Event.ENTER_FRAME, updateScore);
function updateScore(event:Event):void
{
scoreTxt.text = String(score);
}
This will then put the value of the score into the text field as a string and update it every frame.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.