View Full Version : healthbar --> next frame
darksauce
May 14th, 2006, 02:44 AM
hi, i need help with my game and i need help asap. i have a health bar that wen some1 gets hit, it loses 1 health block by fading its alpha to 30. i want it so dat when the last block goes, it plays the next frame, but my code isnt working. plz help! my code:
_root.health1 = 50;
if (this.hitTest(this.target)) {
_root.health1 -= 10;
trace("You hit the target");
this.removeMovieClip();
}
and there are 5 health movieclips, one with <50, <40, <30, <20, and <10 code is:
onClipEvent (enterFrame) {
if(_root.health1<50)
{
this._alpha=30;
}
else{this._alpha=100;
}
}
and the final bit is :
if (_root.health1 == 0 or _root.health1<0) {
nextFrame();
}
plz helps asap!!!
Smee
May 14th, 2006, 05:40 AM
So which part of that code works and which part doesn't?
lone_wild_wolf
May 14th, 2006, 06:02 AM
as far as i can see its allright just try changing the final bit to
if (_root.health1<=0){
nextFrame();
}
Skinny_T
May 14th, 2006, 08:01 AM
I've always had my healthbars as 1 MC then have them scale to the amount of health that the player has left using .xscale
mayjarboi
May 14th, 2006, 08:19 AM
im not if this is what you want but try this
in the frame of your health bar put
ActionScript Code:
_root.health1 = 100;
_root.maxhealth1 = 100;
then put this in the last frame of the enemy "hit" frame or whatever
ActionScript Code:
_root.health1 -= 10;
Smee
May 14th, 2006, 07:50 PM
Come on guys, actually read his question :P
He has 5 blocks, and they fade out one by one when he gets hit. Like hearts in Zelda games but whole hearts instead of half hearts.
I'll make my question more specific.. Is the problem that the blocks aren't fading out at all?
If that's not the case, and they are fading out but it's just not moving to the next frame, are you sure you have "nextFrame()" in the right timeline, and that you don't need a "_root.nextFrame()" instead? Something like this is very hard to answer (if possible at all) without knowing how you have your timelines set up, and which bit of code is on which timeline.
darksauce
May 15th, 2006, 08:35 AM
yes, i hav 5 movie clips dat fade as the player gets hit. but as soon as the health reaches 0, and the last health block fades away, it still is not changing to the next frame. the code for the next frame is in the normal timeline. i cant figure out wats wrong. when the health reaches zero, the game continues on as if nothing happend. plz help!
Smee
May 15th, 2006, 11:00 AM
So the code that checks wether or not the health is gone is not in an onEnterFrame? That could be the problem.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.