PDA

View Full Version : How to make a health bar [Flash][Actionscript]



SpaceBar
11-25-2006, 05:34 AM
So you wanna make a healthbar. This tutorial will show you how. This is the finished product. When the blue circle touches the green square the healthbar will decrease.
http://i68.photobucket.com/albums/i26/Spacebar_Anims/tut.swf height=300 width=400

To start make 2 frames and on the second one put a you lose sign or something.
Put stop(); on both frames
Make 2 movieclips
A character and name it char and a square and name it enemy
To name it go to the properties bar
http://i68.photobucket.com/albums/i26/Spacebar_Anims/Instances.jpg
On the character put this code in it to make it move:


onClipEvent(load){
moveSpeed = 5;
}

onClipEvent(enterFrame){
if(Key.isDown(Key.UP)){
this._y -= moveSpeed;
}
if(Key.isDown(Key.DOWN)){
this._y += moveSpeed;
}
if(Key.isDown(Key.RIGHT)){
this._x += moveSpeed;
}
if(Key.isDown(Key.LEFT)){
this._x -= moveSpeed;
}
}



Now make a health bar. Just make a red rectangle.
Movieclip it buy selecting it and push f8 and name it hp
On the first frame put:
stop();

On every 5 frames make the red rectangle smaller until it dissapears
On the last frame put this:
_root. gotoAndPlay(2);

So this code makes it when your health runs out it redirects you to the *YOU LOSE* frame.

To make the healthbar go smaller when the character touches the square put this code at the end of the code for the character


onClipEvent(enterFrame){
if(this.hitTest(_root.enemy)){
_root.hp.nextFrame();
}
}



Well i made it on Sp so why not post it here?

Houston-Mane
11-25-2006, 06:27 PM
leik omg!!!!!! that will helps me alots.


Anyways thanks for the health bar but im good at making it go down frame by frame nice script by the way........

I might try that.

2-D
11-25-2006, 06:30 PM
There was nothing to click in that flash.

FrAnKeH
11-25-2006, 08:04 PM
A better way is using _xscale.

SpaceBar
11-25-2006, 08:35 PM
yeah
u sed that alrdy

DarkAssassin
11-26-2006, 04:35 AM
yeah
u sed that alrdy

Wy did you put away your awesome dance siggy ?.

SpaceBar
11-26-2006, 09:49 PM
coz ppl didnt like it lol

noogai
11-28-2006, 06:43 AM
thx 4 da help

Deathwish
11-28-2006, 08:36 AM
noogai in your sig it says don't steal you stole the guy who made animator vs animations nickname you dolt.

the silent mage
11-30-2006, 12:53 PM
I can't do this , i don't know why i need help......so spacebar add me on msn and can you send it me to see what i did wrong?please i can't do it from words.......

SpaceBar
12-01-2006, 01:15 AM
you can download the healthbar file here:
http://www.filesend.net/download.php?f=428611d659075e4b15bd98476153374e

the silent mage
12-01-2006, 08:56 AM
thanks that helps thanks alot spacebar

maxwong
12-02-2006, 05:15 PM
noogai in your sig it says don't steal you stole the guy who made animator vs animations nickname you dolt.

Ya lah and he also steals people's swf files , he pretend to ask people than he import them to the libary and use them, he is a stealer!

sethkid009
12-02-2006, 09:32 PM
I tried, but it didn't work!!!! :-( i used stick figs insted of blocks and circles.

jtmurkz
12-03-2006, 07:26 AM
very cool! well done space bar

2.shot.2.kills
12-03-2006, 02:59 PM
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf
http://i136.photobucket.com/albums/q188/Captain_nosebugger/Untitluuuued-1.swf

cprulz
05-17-2007, 11:43 AM
noogai in your sig it says don't steal you stole the guy who made animator vs animations nickname you dolt.


L.M.A.O
L.O.L
R.O.F.L

magicaldragon
05-18-2007, 04:51 PM
good tut
love it
9/10
1 off for crap looking gameishkoio9iyiui thingy tu

figsarecool
06-17-2007, 10:48 AM
I was wondering if you could just make a link to the .fla file that you made for that game. I am having trouble with the health...

figsarecool
06-17-2007, 10:48 AM
I was wondering if you could just make a link to the .fla file that you made for that game. I am having trouble with the health...

Revan
06-02-2008, 01:25 AM
hi... nice work... this really helps me... but i can't seem to get it to work... could you upload it somewhere and send me the link plz

Scarecrow
06-02-2008, 02:25 AM
I think this must be the problem everyone is having:



Now make a health bar. Just make a red rectangle.
Movieclip it buy selecting it and push f8 and name it hp
On the first frame put:
stop();


I believe the text in red there should be
this.stop();
instead.

Rashino
07-13-2012, 05:53 AM
it says that i cannot add action script into the item :( can someone help?