Be a Supporter!

Health regeneration

  • 267 Views
  • 2 Replies
New Topic Respond to this Topic
sonic180
sonic180
  • Member since: Feb. 4, 2006
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Health regeneration 2011-02-03 10:46:10 Reply

I really hate having to post questions, but I have searched google and I did not find anything... So, I have the health bar completely set up. I just want to know how to make it regenerate over time. I do not know if flash has a timer function, so I was using variables. But the problem was, everything worked fine. But when I leveled up, the variable continued counting down, and then when it got to 0, it added more health... I completely deleted the whole timer variable because of this.

I feel that there has to be an easier way, I just don't know how... By the way, I am using AS2. Any help would be greatly appreciated.

PrettyMuchBryce
PrettyMuchBryce
  • Member since: Mar. 17, 2001
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Health regeneration 2011-02-03 10:55:59 Reply

When I used to use AS2 I would do those variables timers like what you're talking about. They work pretty well you just need to add a boolean check if your game ends or if the player dies. So you would do something like.

var healthTicks:int = 0; // these are ticked every frame
var healthMax:int = 30; //how long until health is increased
var health:int = 100; //player health
var isLeveledUp:Boolean = false; //set this to true when you want it to stop going up

//put this stuff in an enterframe
healthTicks++;
if (isLeveledUp==false&&healthTicks>=health Max&&health<=100) {
health++;
healthTicks = 0;
}

Flash does have a timer class, but this won't really solve the problem you're having. It's been a long time since I did AS2 so this is really just psuedo code. Hope it helps.


BBS Signature
Marsume
Marsume
  • Member since: Oct. 22, 2006
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Health regeneration 2011-02-03 11:09:16 Reply

setInterval?
http://www.republicofcode.com/tutorials/
flash/setinterval/