The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsHi guys,
I am making a simple little game in flash and I would like a health bar to go in it, what I need is a bar which I can control as required frame by frame on a + or - basis - so one frame could contain 'you get hit by a brick, lose 10 health' or another could contain 'you drink a health potion, gain 20 health'. I also need some way of checking the health bar so that when it reaches 0 the player is directed to a certain frame.
I have checked out a bunch of tutorials online but they have all been based on a collision system to reduce health, but my game will be text based. Being a total novice, I haven't been able to translate these tutorials into what I need.
I am okay with the visual side of things (making the bar and splitting the stroke into a separate layer etc.) but if anyone could help me with the code I would be very grateful!
Best,
Ben
The simplest method you could use that has as little AS as possible, is to keep all the frames in your health bar movieclip, and just whenever anything happens that will make u get hurt, tell the _root.health.gotoAndStop(#):
replace # with frame number
At 5/3/09 02:43 PM, greyheaven wrote: Hi guys,
I am making a simple little game in flash and I would like a health bar to go in it, what I need is a bar which I can control as required frame by frame on a + or - basis - so one frame could contain 'you get hit by a brick, lose 10 health' or another could contain 'you drink a health potion, gain 20 health'. I also need some way of checking the health bar so that when it reaches 0 the player is directed to a certain frame.
I have checked out a bunch of tutorials online but they have all been based on a collision system to reduce health, but my game will be text based. Being a total novice, I haven't been able to translate these tutorials into what I need.
I am okay with the visual side of things (making the bar and splitting the stroke into a separate layer etc.) but if anyone could help me with the code I would be very grateful!
Best,
Ben
I'm quite sure what you mean - do you want a bar that displays health, or just text...?
Anyway, if you want a health bar, draw it, and then simply adjust its _xscale property to reflect the health.
e.g. healthBar._xscale = health;
For running out of health:
If (health <= 0)
{
gotoAndStop(frame); // or whatever
}
Hi 4urentertainment,
Thanks for your reply! As far as I realise, I need to have the bar working a bit more dynamicly than that, because my game will comprise of a lot of unique frames on a different layer which will tell the 'story' as such - if that makes sense!
Cheers
Hi Neo-13,
Thanks for your help, I do want a visual health bar, with no text. I have used Xscale to display the value of my health variable but I am having trouble adjusting the health as I go along, the bar doesn't seem to move so assuming I coded the bar correctly the value of my 'health' is being lost somewhere :/
You probaly aren't checking whether the health has changed. In other words, you're probably only telling the xscale of the bar to equal the health at the beginning, but when the health changes, the code needs to be executed again. Therefore, you will need to execute that code every frame, using the onEnterFrame function.
on your enterframe, do a:
trace(health);
to make sure the variable itself is working correctly.
Once it is, then implement the above health bar.
Perpetually looking for time to return to the arts.
Hey guys,
Still no success, perhaps someone can help me out, I have this code on the 'energyBar' graphic:
onClipEvent(load){
var energy = 100;
var maxenergy = energy;
}
onClipEvent(enterFrame){
energyBar._xscale = (energy / maxenergy) * 100;
}
I can't tell if its working or not, also when I want to make the health go up or down on certain frames I am trying to use:
onClipEvent(load){
energy -= 10;
}
on the health bar layer and graphic, am I doing this correctly?
Thanks again, I'm sure this is very simple for you guys but as a total novice I am finding it confusing! :)
Cheers
based on that code, we're gonna need more info. where is your health variable? what happens when u trace it? how do u tell the program to lessen health?
Sorry if I am explaining badly, hopefully this picture can illustrate what I am trying to do:
My energy bar starts on frame 50, before that is a preloader on frames 1+2 and an intro, from 50 is the one you can see, with 51 and 52 being frames displaying the outcome of each choice seen on frame 50, hopefully this makes things a bit clearer!
Cheers
ok, assuming the 50 frames are already correct (going smaller) and your health is out of 100. Inside the health bar (double click on it) make a new layer. Make sure it only has one keyframe on that layer and put this in the keyframe put the following actions (as2)
onEnterFrame = function () {
gotoAndStop(_root.health/2);//change health to the variable that ur using, and take out the /2 if ur health
//and amount of frames is the same
}; guys, take the easiest way in!
what code are you giving him?
gotoAndStop?
health=80;
maxHealth=100;
healthBar._xscale=Math.floor((health/maxHealth)*100);