View Full Version : health bar help
pyroki
June 19th, 2005, 03:01 PM
like always im having problems well not too big neways. i made a healthbar and when the enemy hits the hero it gets longer i know why which is bcause i put if enemy hitest the hero for the healthbar to _xscale += 5 but it looks messed up bcause it is getting longer so is there a way for only one side of the bar to come in or just simple question how do u make a health bar go down.
foodpk
June 19th, 2005, 04:11 PM
You should keep track of hit points. Then when your character gets hit or takes a health potion, just adjust the healthbar according to the relationship between maximum health and current health. Like so.
healthbar._width = (current_hp/max_hp)*100;
Soul814
June 19th, 2005, 04:26 PM
yeps what he said =D, well 100 would be your length of the bar, i might be wrong but in preloaders i remember i did it by the length of my bar
pyroki
June 21st, 2005, 07:23 PM
k i get wut u mean but how do i write it i just tried writing it like this and it didn't work.
onClipEvent(load) {
hp = 100;
maxhp = 100;
}
onClipEvent(enterFrame) {
this._width = (hp/maxhp)*100;
if(hero.hitTest(police._x, police._y)) {
hp -= 5;
}
}
pyroki
June 21st, 2005, 07:34 PM
nvm it works but it still goes down from both sides :*(
cholin
June 21st, 2005, 07:54 PM
It goes down from both sides because youre changing a movie clip. I think it might not if you set the registration point to the one side, otherwise you will have to constantly set the _x variable every time it changes.
pyroki
June 21st, 2005, 08:10 PM
thx cholin one last thing how can i get it to go and play my game over screen if it reaches 0
cholin
June 21st, 2005, 08:11 PM
Pseudo-code:
if (_root.health == 0)
{
gotoAndStop("Game_over_scene", 1);
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.