Quote from SpaceBarSo 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
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?