00:00
00:00
Newgrounds Background Image Theme

LOCKdev just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS: Bars (Health/etc)

13,951 Views | 59 Replies
New Topic Respond to this Topic

Response to AS: Bars (Health/etc) 2005-12-11 12:25:38


If you want to declare a health variable too in only the character (spaceship) MC:

onClipEvent(load){
health=100;
}
onCLipEvent(enterFrame){
if (hitTest(_root.enemy1)){
health--;
}
_root.healthbar._width=health;
}

There you go. Just remember to make a MC and call it healthbar which will be the health bar ;)

~GWHC


BBS Signature

Response to AS: Bars (Health/etc) 2005-12-11 12:29:28


Cool, So where would this go?


...

Response to AS: Bars (Health/etc) 2005-12-11 12:36:59


OnClip Events cannot be in other OnClip events.

That is what came up.

So I guess that you need to seperate the OnClipEvent (Load) from the OnClipEvent (enterframe)


...

Response to AS: Bars (Health/etc) 2005-12-11 12:48:12


Oh sry. Big L :P
Anyway this should be in your player AS:

onClipEvent(load){
health=100;
}
onClipEvent(enterFrame){
if (hitTest(_root.enemy1)){
health--;
}
_root.healthbar._width=health;
}


BBS Signature

Response to AS: Bars (Health/etc) 2005-12-11 13:11:21


I understand .

And it worked thanks.

Now, for like health, I need a code that when you get an upgrade, your health increases.

So would it be the opposite of the collision?


...

Response to AS: Bars (Health/etc) 2005-12-11 14:00:09


I have a problem with my health bar. It works and everything, but when it gets to zero, I want it to go and stop at my "game over" scene. But the script I try doesn't work.

if (_root.health == 50) {
gotoAndStop("Game Over");
}


BBS Signature

Response to AS: Bars (Health/etc) 2006-01-19 09:55:57


Okay, I'm trying to work with "23450" health bar, but I can't figure out what to do for adding or subtracting. I have a button that I made that has this action applied to it:

on (release) {_root.remaining -= 10;
}

I tried a few other things as well, but I can't figure it out.

Response to AS: Bars (Health/etc) 2006-01-19 09:58:55


Use your code but change the bar's code to:
onClipEvent (load) {
_root.total = 100;
_root.remaining = 100;
}
onClipEvent (enterFrame) {
this._xscale= _root.remaining/_root.total*100
}


BBS Signature

Response to AS: Bars (Health/etc) 2006-01-23 01:40:54


thanks, that actually helps a lot.

Response to AS: Bars (Health/etc) 2006-01-23 03:34:59


At 12/11/05 01:11 PM, -Rule- wrote: I understand .

And it worked thanks.

Now, for like health, I need a code that when you get an upgrade, your health increases.

make you're upgrade thing a box that you have to hit and have this code on the box:
onClipEvent(enterFrame){
if(this.hitTest(_root.guy)){
_root.guy.health=150
}
}


========|| WWWWWWWW>[-[Blog] - [Audio] - [Userpage] - [Flash] - [Last.fm]-]<WWWWWWWW ||========

BBS Signature

Response to AS: Bars (Health/etc) 2006-02-23 11:48:16


sure there is, change :

onClipEvent(enterFrame){
this._width=_root.score;
}

to

onClipEvent(enterFrame){
this._width+=(_root.score>this._width) + ((_root.score<this._width)*-1);
}

Response to AS: Bars (Health/etc) 2006-02-23 11:53:37


At 2/23/06 11:48 AM, Inglor wrote: this._width+=(_root.score>this._width) + ((_root.score<this._width)*-1);

Nifty. I need to work on cutting down on if statements... ;)


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

Response to AS: Bars (Health/etc) 2006-02-23 11:56:18


No offense but this type of negating disturbs me:
(_root.score<this._width)*-1

Just use -(_root.score<this._width) damnit >=)


BBS Signature

Response to AS: Bars (Health/etc) 2006-02-23 11:57:59


At 12/11/05 12:06 PM, -Rule- wrote: if (hitTest(_root.enemy1)==true)

{_root.healthbar.

Then what?

put this=
if (this.hitTest(_root.enemy1)){
_root.healthbar._xscale-=10;
}
on the ship mc

Response to AS: Bars (Health/etc) 2006-02-23 13:02:00


what do you mean wabbling? upload a sample

Response to AS: Bars (Health/etc) 2006-02-23 13:07:36


Try using this instead:

this._width += (_root.health > Math.round (_width)) - (_root.health < Math.round (_width));


BBS Signature

Response to AS: Bars (Health/etc) 2006-02-23 17:02:41


The second one overwrites the first, have them both in the same:

function onEnterFrame () {
if (_root.health >= 250) {
_root.health = 250;
}
if (_root.health <= 0) {
_root.health = 0;
}
}

You could also simplify it a bit:
function onEnterFrame () {
_root.health = Math.max (0, Math.min (_root.health, 250));
}


BBS Signature

Response to AS: Bars (Health/etc) 2006-04-30 21:21:44


ok, man, obviously you dont understand how this works. Which is ok. We all learn somewhere.
:are you ready to learn??!!
Ok. Here.

Make a bar, and put these actions in the bars actions panel

onClipEvent(enterFrame){
this._width=_root.health;
}
there bow put these actions in your player

onClipEvent(enterFrame){
if(this.hitTest(enemy1)==true){_root.healt
h -=10;}}
:this will work
this is telling the player MC that when it touches the instance of 'enemy1' to make the health bar go down ten. Now, ad this to the code.
onClipEvent(enterFrame){
if(_root.health==0){_root.gotoAndStop('gam
eover')}
:there ya go.
So the finished code would be

onClipEvent(enterFrame){if(this.hitTest(
_root.enemy1)==true){
_root.health -=10;}
onClipEvent(enterFrame){if(root.health==0;
){gotoAndStop('gameover')}}

:im pretty sure this will work, i tested it out with Flash MX though

i hope it helped!!!!=P


Steam: imuffin101

BBS Signature

Response to AS: Bars (Health/etc) 2006-05-06 08:06:16


This tut is on the condition of keeping the same max health or whatever the same the whole time, so that the bar never gets longer than 100. What if, you wanted the bar to stay the length of 100 but wanted to go to higher numbers in the situation of lvling up in an rpg or something. Because if you get enough hp, the bar will become too big for the screen. Any help here?

Response to AS: Bars (Health/etc) 2006-08-26 11:56:11


what would the code be if I wanted it to do something if health hit 0

Response to AS: Bars (Health/etc) 2007-12-09 15:16:27


At 11/13/05 01:18 PM, Trippy-Hippie wrote: for the regenerating bar, is there a backwards version? I mean, i need a bar that goes down by NOT doing anything, and gains score by hitting a key or something.

heres the example of what you want

Response to AS: Bars (Health/etc) 2008-08-12 03:12:09


just for anyone that dosent quite understand this tut i found a LOT easer one here:
http://www.flashkit.com/tutorials/Games/
Health_f-CorkySur-1129/index.php


hey i know your reading this! ya you, you know im talking about u here. its about you!

its the truth!

BBS Signature

Response to AS: Bars (Health/etc) 2009-10-11 18:42:54


At 7/25/05 07:42 PM, Inglor wrote:
Congrats, we have created a working bar... currently it's aligned to the center, but you can also align it to the right by adding this._x=baseX+this._width/2

Sorry for bumping but...
using this._x=baseX+this._width/2 isn't that nessessary. You could just align the health bars registration point to the right of the health bar.

There is many ways of doing 1 thing. I suggest this way.

Response to AS: Bars (Health/etc) 2009-11-23 19:43:18


Yo, actually. If you want the bar to be alligned to the left or right, you could just easily move it so that little handy "+" is on the left or right (left side if you want it to extend rightwards, and vise-versa).


Excuse me if my 'level' decieves you and puts me off as a noob. For clerifacation, I just dont browse Newgrounds enough to boost it, but I have 5 years of Flash experience.

Response to AS: Bars (Health/etc) 2009-11-23 19:50:36


At 11/23/09 07:43 PM, Pie-4Ever wrote: Yo, actually. If you want the bar to be alligned to the left or right, you could just easily move it so that little handy "+" is on the left or right (left side if you want it to extend rightwards, and vise-versa).

Month late on that one, man. Sorry :/


MY E-PENIS IS BIGGER THAN YOURS

8=================================>

...and this is my fag...

BBS Signature