How do you make a health bar
Printable View
How do you make a health bar
Hey I dont know why but FlashKit is losing its touch and no one really replies any more. But ill help you. What are your instance names of the controlled character and the life bar you make. Then i can figure out a code for you to use. Oh and what game is it too a fighter, RPG etc.
Its a shooting game, and the enemys instances are "bad"
Hey He is very busy So maybe just go on msn ill talkmto u and see what i can for u My hotmail is
MSN [email protected]
AIM Coolazz0
Couldent Ya just tell me how to make a health bar?!
hello, dawg ^^
i'll try to help you with this.
1) create a MC you call "HealthBar" (of course, draw you health bar in it). put it where you want.
2) now put something like this on your ship MC, under onClipEvent enterFrame:
if(hitTest(_root.bad))(
_root.healthBar._xscale-=1
)
i wrote the code by myself, maybe there are one or two syntax errors, but that's what that code mean:
everytime a "bad" touches you, your health bar becomes shorter. _xscale means that the x axis of your health bar become little with each hit.
this is very basic of course, you'll need to work it better maybe in the future.
I did somethign similar to marmotte's:
You can change the values, to anything, though with my clip, it only worked when the _width value was twice the _x value.Code:if(hitTest(_root.bad)){
this._width -= 2;
this._x -= 1;
}
Ah, thank you. One more question, do you know how to make it go to another frame when it gets to a certain point or size?
sorry to bring this from the grave
I made something similar to marmotte, but I cant get it to go to a frame in my case frame 4 when the health bar reaches 0 how can I do this?
I prefer to track health as a number from 0 to 100 and then I set the health bar's _xscale to the value. Like this:
MCplayerHealth._xscale = playerHealthValue;
I like your way ray though would prefer to stick to my way if possible but still does not help me as I cant get it to link to frame 4 when it reaches 0 in my case when life.xscale = 0
Anyway got any ideas as Im still learning so not great anyways been an animator though really want to get in to game design.
if you are doing the check in a if then, then u gotta do if(life.xscale <= 0) or if(life.xscale == 0) i would use the first one.
so it would be
if(life.xscale <= 0){
gotoAndStop(4);
}
Tired and just tired that again still no luck seem to make you auto fail I am off to work now will try again if no luck I will post the complete code and if anyone whats me to post the source file I will as well.
Maybe the main timeline needs to go to frame4 in which case you have to use _root.gotoAndStop(4) or _level0.gotoAndStop(4)
Make sure you are using all organic ingredients and no processed crap.
I tried different items I dont know why none work seems to be common on the Mac flash never had these issues when I use to work on Pc, though I did get it to work in the end so anyone that is interested, though using a text value for life so Health starts 100 and when reaches 0 goes to such and such frame.
lifetext = 100;
this.onEnterFrame = function(){
trace(_level0.lifetext);
if(_level0.lifetext <= 0){
this.gotoAndStop("fail");
}
};
Incase any one wants to use my code.
lifetext = 100; - this is a dynamic text box with the instance name of lifetext, it states to start at 100
this.onEnterFrame = function(){
trace(_level0.lifetext);
if(_level0.lifetext <= 0){ - Lifetext is equal to or less than 0
this.gotoAndStop("fail"); - go to and stop frame name fail
}
};
Hey there is a nice tutorial on this at freshnova, here is a link http://www.freshnova.com/Flash-Tutor...flashgame.html Hope I am allowed to post links here and of course I hope this helps you and any one else that stumbles upon this.:)
yes we give you permission lolz
Please play the attached .FLA (F8).
Bump
it means he just "necroed" it bringing this post back to the top and yea im doing the same
Nice.
Hm, Marmotte was pretty timid about his coding skills 8 years ago. :shhh:
not sure if this is comparable, but Im making a spot the difference game and I need a time bar, can I use something similair to the code of this health bar ? Of course it's not hittest related tho, but it should influence the score
You can use this:http://blog.bluemagica.com/?p=11
just create it with the maximum time, and then update with the time remaining value.
looks cool, thanks :)
Wow its nice to look back seeing how much progress I have gone though looks like I might get stuck on the forums again
Just set up two distinct health variables for them - don't call the variable health, that is taken by default. To draw the health bar use different coloured draw_rectangle, or a sprite based health bar by drawing part of the image.
there are a few ways to make health bar.. my favorite:
1. draw a long rectangle
2. make it a movie clip
3. tween the inside color to make it look like the health is decreasing..
4. at the end of the movie clip where the health runs out.. tell it to go to "fail"
5. at beginning.. tell it to stop.. or else it will just play and not work.
6. where you code collisions and hits to your character.. tell the health bar movie clip to advance one frame..
check out how it works in this game i made
http://blueco.ws/ShootingGame
Just set up two distinct health variables for them - don't call the variable health, that is taken by default. To draw the health bar use different coloured draw_rectangle, or a sprite based health bar by drawing part of the image.
I can't understand...