Stick Page Forums Archive

How to make a health bar [Flash][Actionscript]

Started by: SpaceBar | Replies: 22 | Views: 6,333

SpaceBar

Posts: 82
Joined: Apr 2006
Rep: 10

View Profile
Nov 25, 2006 12:34 PM #18805
Quote from SpaceBar
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.
[SWF="http://i68.photobucket.com/albums/i26/Spacebar_Anims/tut.swf height=300 width=400"]http://i68.photobucket.com/albums/i26/Spacebar_Anims/tut.swf height=300 width=400[/SWF]

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
Image
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

Posts: 0
Joined: Jul 2025
Nov 26, 2006 1:27 AM #18830
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
2

Posts: 12,355
Joined: Sep 2006
Rep: 10

View Profile
Nov 26, 2006 1:30 AM #18831
There was nothing to click in that flash.
FrAnKeH
2

Posts: 602
Joined: Aug 2005
Rep: 91

View Profile
Nov 26, 2006 3:04 AM #18832
A better way is using _xscale.
SpaceBar

Posts: 82
Joined: Apr 2006
Rep: 10

View Profile
Nov 26, 2006 3:35 AM #18833
yeah
u sed that alrdy
DarkAssassin
2

Posts: 37
Joined: Nov 2005
Rep: 10

View Profile
Nov 26, 2006 11:35 AM #18845
Quote from SpaceBar
yeah
u sed that alrdy


Wy did you put away your awesome dance siggy ?.
SpaceBar

Posts: 82
Joined: Apr 2006
Rep: 10

View Profile
Nov 27, 2006 4:49 AM #18905
coz ppl didnt like it lol
noogai
2

Posts: 12
Joined: Nov 2006
Rep: 10

View Profile
Nov 28, 2006 1:43 PM #18941
thx 4 da help
Deathwish
2

Posts: 3,793
Joined: May 2006
Rep: 10

View Profile
Nov 28, 2006 3:36 PM #18943
noogai in your sig it says don't steal you stole the guy who made animator vs animations nickname you dolt.
the silent mage
2

Posts: 34
Joined: Aug 2006
Rep: 10

View Profile
Nov 30, 2006 7:53 PM #19013
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

Posts: 82
Joined: Apr 2006
Rep: 10

View Profile
Dec 1, 2006 8:15 AM #19031
you can download the healthbar file here:
http://www.filesend.net/download.php?f=428611d659075e4b15bd98476153374e
the silent mage
2

Posts: 34
Joined: Aug 2006
Rep: 10

View Profile
Dec 1, 2006 3:56 PM #19036
thanks that helps thanks alot spacebar
maxwong

Posts: 0
Joined: Jul 2025
Dec 3, 2006 12:15 AM #19113
Quote from death_wish
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

Posts: 0
Joined: Jul 2025
Dec 3, 2006 4:32 AM #19122
I tried, but it didn't work!!!! :-( i used stick figs insted of blocks and circles.
jtmurkz

Posts: 0
Joined: Jul 2025
Dec 3, 2006 2:26 PM #19127
very cool! well done space bar
Website Version: 1.0.4
© 2025 Max Games. All rights reserved.