View Full Version : Healthbar for fighting game
emilio7
August 28th, 2008, 03:49 PM
Hi everyone, am develop a fighting game, am using Flash Pro 8, an Mortal Kombat game, exactly. The point is that i want to make 2 healthbars, one for the user/player and other for the computer/enemy, i found a few codes for this in the web, but none help me. I build the healthbar, using this page (http://www.how2flash.com/tutorials/Fighting%20Game/). But, i want to make that when the bar reaches 0, the movie GotoAndStop, a frame who told the player: "game over", for example, if the enemy healthbar reaches 0, GotoAndStop frame labeled "win", and if the healthbar of the player reaches 0, GotoAndStop frame labeled "loose".
Can anybody help me here?
sam_vickery
August 28th, 2008, 05:12 PM
hi
I have made some simple health bars that work and I dont know if there what you are looking for. if you need any more help pm me
cheers
emilio7
August 28th, 2008, 05:52 PM
hi
I have made some simple health bars that work and I dont know if there what you are looking for. if you need any more help pm me
cheers
Thanks dude!
Here is the final code, in case someone wants:
(in the movie clip of the health bar)
onClipEvent (enterFrame) {
this._xscale = _root.enemy_hp;
if (_root.enemy_hp<=0) {
_root.enemy_hp = 0;
if (_root.enemy_hp<=0) {
_root.gotoAndPlay("gameover");
}
}
}
"Enemy" is the var name of the enemy.
"gameover" is the labeled frame of game over.
Oh! BTW, first you have to define your enemy`s health, add this code to the frame that contains the fighting sisteam:
enemy_hp=100;
Also, you need to create a dynamic text, and give him the instance name and var:
enemy_hp, and thats it! :}
SparK_BR
August 29th, 2008, 11:43 PM
if (_root.enemy_hp<=0) {
_root.enemy_hp = 0;
if (_root.enemy_hp<=0) {
_root.gotoAndPlay("gameover");
}
}
should be
if (_root.enemy_hp<=0) {
_root.enemy_hp = 0;
_root.gotoAndPlay("gameover");
}
try to make the enemy object to know his hp
int _root.enemy.health;
then you don't need texts to hold data, only to show it!
goodluck! ;)
substance
August 31st, 2008, 09:16 PM
I made a health bar not too long ago as well.
example (http://teamimpulse9.com/hbar%20test.swf)
function clickHandler(event:MouseEvent):void {
var difference:Number = currentHealth / maxHealth;
var redMultiplier:Number = 1 - difference ;
var greenMultiplier:Number = difference;
TweenLite.to(HEALTH_BAR,.4,{scaleX:difference})
HEALTH_BAR.transform.colorTransform = new ColorTransform(redMultiplier,greenMultiplier,0);
}
Unfortunately I never figuired out how to tween the color transform.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.