Copy link to clipboard
Copied
Hi,
I am fairly new to ActionScript and i have recently started making a game in which you dodge falling enimies.
Does anyone know how i would make the score constantly count up?
And then stop when i hit an enemy.
Thanks.
then use the timer class:
var t:Timer=new Timer(1000,0);
t.addEventListener(TimerEvent.TIMER,timeF);
t.start();
// use t.stop() when you hit an enemy
function timeF(e:TimerEvent):void{
// you can use t.currentCount
}
Copy link to clipboard
Copied
it's easiest to use a number or int variable to keep the current score. eg,
var score:int = 0;
// and whenever you want to increase the score, call incrementScoreF and pass the amount to increment.
function incrementScoreF(n:int):void{
score+=n;
}
Copy link to clipboard
Copied
Thanks for the advice.
But all i really need is basically just a timer, counting up from 0.
Copy link to clipboard
Copied
then use the timer class:
var t:Timer=new Timer(1000,0);
t.addEventListener(TimerEvent.TIMER,timeF);
t.start();
// use t.stop() when you hit an enemy
function timeF(e:TimerEvent):void{
// you can use t.currentCount
}
Copy link to clipboard
Copied
Thanks for the advice, this worked.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now