PDA

View Full Version : Flash problem I forgot how to go about.



tjmoore1993
January 26th, 2008, 10:20 PM
Hello, I been making this game I seen a tutorial on it but I am not going to copy it but It had something I wanted so I copied just 1 thing it's been bugging me though I can't seem to change frame when the HP is 0 I need help anyone?

This is my HP Bar


onClipEvent (enterFrame) {
this._xscale = _root.Enemy_1_Hp;
if (_root.Enemy_1_Hp<=0) {
_root.Enemy_1_Hp = 0 ;
}
}


This is my Frame script to make sure that the HP is set to 100.


Enemy_1_Hp = 100;


I got it nevermind.

I just took the script

onClipEvent (enterFrame) {
this._xscale = _root.Enemy_1_Hp;
if (_root.Enemy_1_Hp<=0) {
_root.Enemy_1_Hp = 0 ;
}
}

and edited to this

onClipEvent (enterFrame) {
this._xscale = _root.Enemy_1_Hp;
if (_root.Enemy_1_Hp<=0) {
_root.Enemy_1_Hp = 0 ;
_root.gotoAndStop(5) // This is where I got confused but I manage to get it =]
}
}

therobot
January 27th, 2008, 07:34 PM
Just a suggestion to help the frame rate of your game. Instead of having your HP bar be updated every single frame (onEnterFrame), have it update only when certain events happen that cause it to change.

I used to go about my coding just having everything happen with an onEnterFrame. These will add up quickly and cause your game to run slower than it really needs to.

Example from your code


if (playerHit) {
updateStatusBar(-5, _root.enemy1HP, _root.enemy1HPBar);
}

function updateStatusBar(damage:Number, whichCharacter:MovieClip, whichStatusBar:MovieClip) {
whichCharacter.hp += damage;
whichStatusBar._xscale = whichCharacter.hp;
if (whichCharacter.hp <=0) {
whichCharacter.hp= 0 ;
_root.gotoAndStop(5) // This is where I got confused but I manage to get it =]
}
}