Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to make energy bar increase by 1 each minute and set a timer for it?

New Here ,
Oct 31, 2014 Oct 31, 2014

Hi,

how i can set a time for an energy bar like what you can see in facebook games?

and make it increase the energy bar value by 1 for each minute?

TOPICS
ActionScript
432
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 31, 2014 Oct 31, 2014

You can use the Timer class to have a Timer object repeatedly execute a function every minute.  You define the Timer....

var energyTimer:Timer = new Timer(60000);  // one minute delay - repeats indefinitely

energyTimer.addEventListener(TimerEvent.TIMER, addEnergy);

function addEnergy(evt:TimerEvent):void {

     // adjust the energy value and the displays of it here

}

energyTimer.start();  // use when you want the Timer to begin

Translate
LEGEND ,
Oct 31, 2014 Oct 31, 2014

You can use the Timer class to have a Timer object repeatedly execute a function every minute.  You define the Timer....

var energyTimer:Timer = new Timer(60000);  // one minute delay - repeats indefinitely

energyTimer.addEventListener(TimerEvent.TIMER, addEnergy);

function addEnergy(evt:TimerEvent):void {

     // adjust the energy value and the displays of it here

}

energyTimer.start();  // use when you want the Timer to begin

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2014 Oct 31, 2014

and i shall use energytimer.stop() to stop it when it full, well thank you Ned, was very helpful

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 31, 2014 Oct 31, 2014

You can stop it or you can put a condition in the function that inhibits adding more when the maximum is reached.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2014 Oct 31, 2014

i don't know if that will work with my case, because there's no maximum, the player can have more than the full value by some ways, but the timer shall stop at the full value and full value+, i'm not sure about stopping the timer when the real value become more than the full value, i will give it a try if failed i think i will set anther q.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 01, 2014 Nov 01, 2014
LATEST

If you would havr some condition that would stoip the timer then that same condition can be used to prohibit the event handler function from processing anything while the timer continues running.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines