Be a Supporter!

As3 score won't stop going up

  • 171 Views
  • 2 Replies
New Topic Respond to this Topic
bitcubes
bitcubes
  • Member since: Nov. 29, 2013
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
As3 score won't stop going up 2014-02-16 21:56:13 Reply

this.addEventListener(Event.ENTER_FRAME, enterf);
function enterf(e:Event)
{
	score +=1;
score_txt.text = String(score);
}

after it reaches the frame that this code is in, it keeps going up and never stops, I just want it to go up once how do I do this?

Etherblood
Etherblood
  • Member since: Apr. 14, 2013
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to As3 score won't stop going up 2014-02-16 22:06:14 Reply

At 2/16/14 09:56 PM, bitcubes wrote: this.addEventListener(Event.ENTER_FRAME, enterf);
function enterf(e:Event)
{
score +=1;
score_txt.text = String(score);
}

after it reaches the frame that this code is in, it keeps going up and never stops, I just want it to go up once how do I do this?

The EnterFrame-Event is triggered once every frame, so if your game runs at 24 fps the function enterf will run 24 times per frame until you remove the eventListener.

if you just want to increase the score by once by 1 when entering a keyframe, the code

score +=1;
score_txt.text = String(score);

should suffice.

Etherblood
Etherblood
  • Member since: Apr. 14, 2013
  • Offline.
Forum Stats
Member
Level 12
Game Developer
Response to As3 score won't stop going up 2014-02-16 22:07:34 Reply

At 2/16/14 10:06 PM, Etherblood wrote: will run 24 times per frame until

meant 24 times per second