A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: How do you make a health bar

  1. #1
    Sexy beast
    Join Date
    Apr 2002
    Location
    Georgia
    Posts
    119
    How do you make a health bar

  2. #2
    Time Killer sspskater's Avatar
    Join Date
    Jun 2002
    Location
    Closer to u then u think
    Posts
    493
    Hey I dont know why but FlashKit is losing its touch and no one really replies any more. But ill help you. What are your instance names of the controlled character and the life bar you make. Then i can figure out a code for you to use. Oh and what game is it too a fighter, RPG etc.

  3. #3
    Sexy beast
    Join Date
    Apr 2002
    Location
    Georgia
    Posts
    119
    Its a shooting game, and the enemys instances are "bad"

  4. #4
    coolazz
    Guest
    Hey He is very busy So maybe just go on msn ill talkmto u and see what i can for u My hotmail is

    MSN Coolazz0@hotmail.com

    AIM Coolazz0

  5. #5
    Sexy beast
    Join Date
    Apr 2002
    Location
    Georgia
    Posts
    119
    Couldent Ya just tell me how to make a health bar?!

  6. #6
    DOT-INVADER marmotte's Avatar
    Join Date
    May 2002
    Location
    Dot-Switzerland
    Posts
    2,601
    hello, dawg ^^

    i'll try to help you with this.

    1) create a MC you call "HealthBar" (of course, draw you health bar in it). put it where you want.

    2) now put something like this on your ship MC, under onClipEvent enterFrame:

    if(hitTest(_root.bad))(
    _root.healthBar._xscale-=1
    )

    i wrote the code by myself, maybe there are one or two syntax errors, but that's what that code mean:
    everytime a "bad" touches you, your health bar becomes shorter. _xscale means that the x axis of your health bar become little with each hit.
    this is very basic of course, you'll need to work it better maybe in the future.

  7. #7
    Sexy beast
    Join Date
    Apr 2002
    Location
    Georgia
    Posts
    119
    Ah, thank you. One more question, do you know how to make it go to another frame when it gets to a certain point or size?

  8. #8
    Senior Member
    Join Date
    Feb 2001
    Posts
    233
    I did somethign similar to marmotte's:

    Code:
    if(hitTest(_root.bad)){ 
    this._width -= 2;
    this._x -= 1;
    }
    You can change the values, to anything, though with my clip, it only worked when the _width value was twice the _x value.

  9. #9
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    sorry to bring this from the grave

    I made something similar to marmotte, but I cant get it to go to a frame in my case frame 4 when the health bar reaches 0 how can I do this?

  10. #10
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    I prefer to track health as a number from 0 to 100 and then I set the health bar's _xscale to the value. Like this:

    MCplayerHealth._xscale = playerHealthValue;

  11. #11
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    I like your way ray though would prefer to stick to my way if possible but still does not help me as I cant get it to link to frame 4 when it reaches 0 in my case when life.xscale = 0

    Anyway got any ideas as Im still learning so not great anyways been an animator though really want to get in to game design.

  12. #12
    Now tell me whos watchin...... samvillian's Avatar
    Join Date
    Feb 2007
    Location
    Where do you live?
    Posts
    539
    if you are doing the check in a if then, then u gotta do if(life.xscale <= 0) or if(life.xscale == 0) i would use the first one.

    so it would be

    if(life.xscale <= 0){
    gotoAndStop(4);
    }
    If the only tool you have is a hammer, you tend to see every problem as a nail.

    Xbox 360 Modding Controller PS3 Mod Paint Spray LED Case

  13. #13
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    Tired and just tired that again still no luck seem to make you auto fail I am off to work now will try again if no luck I will post the complete code and if anyone whats me to post the source file I will as well.

  14. #14
    Senior Member
    Join Date
    Sep 2004
    Posts
    633
    Maybe the main timeline needs to go to frame4 in which case you have to use _root.gotoAndStop(4) or _level0.gotoAndStop(4)

    Make sure you are using all organic ingredients and no processed crap.

  15. #15
    Senior Wabbit
    Join Date
    Jul 2008
    Location
    Winchester, Uk
    Posts
    215
    I tried different items I dont know why none work seems to be common on the Mac flash never had these issues when I use to work on Pc, though I did get it to work in the end so anyone that is interested, though using a text value for life so Health starts 100 and when reaches 0 goes to such and such frame.

    lifetext = 100;
    this.onEnterFrame = function(){
    trace(_level0.lifetext);
    if(_level0.lifetext <= 0){
    this.gotoAndStop("fail");
    }
    };


    Incase any one wants to use my code.

    lifetext = 100; - this is a dynamic text box with the instance name of lifetext, it states to start at 100
    this.onEnterFrame = function(){
    trace(_level0.lifetext);
    if(_level0.lifetext <= 0){ - Lifetext is equal to or less than 0
    this.gotoAndStop("fail"); - go to and stop frame name fail
    }
    };

  16. #16
    Junior Member
    Join Date
    Feb 2009
    Posts
    1

    tutorial on energy bar

    Hey there is a nice tutorial on this at freshnova, here is a link http://www.freshnova.com/Flash-Tutor...flashgame.html Hope I am allowed to post links here and of course I hope this helps you and any one else that stumbles upon this.

  17. #17
    my x booty it is that BIG
    Join Date
    Jun 2004
    Location
    New York
    Posts
    696
    yes we give you permission lolz
    Project||[GAME]-on hold for now
    ------------------
    [Hero]-80%
    [Enemies]-1%
    [Weapons]-90%
    [Items]-0%
    [Levels]-10%

  18. #18
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Please play the attached .FLA (F8).
    Attached Files Attached Files
    <signature removed by admin>

  19. #19
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Bump
    http://www.birchlabs.co.uk/
    You know you want to.

  20. #20
    When in doubt ask Eager Beaver's Avatar
    Join Date
    Feb 2007
    Location
    Planet Earth
    Posts
    911
    Quote Originally Posted by VENGEANCE MX View Post
    Bump
    Can't understand your post!
    <signature removed by admin>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center