Displaying Health Bars

butterbeanbutterbean Member Posts: 4,315
edited November -1 in Working with GS (Mac)
How could you display health bars say in the left corner of the game screen, and add a a graphic of some sort displaying 3 health bars, and each time the player gets hit, one health bar is taken away.

Comments

  • JGary321JGary321 Member Posts: 1,246
    I assume kinda like Zelda does with the hearts system.

    Theres probably a few ways. One is to create 3 image files. 1 image for 3 hearts, 1 for 2 etc... This will still work with your player lives attribute.

    Set rule so player lives =3, it shows 3 hearts image, another rule so if player lives = 2 change image to 2 hearts image, etc... this should work. maybe not the most efficient but it should do.
  • quantumsheepquantumsheep Member Posts: 8,188
    Take a look at the 'Asteroids' template - it uses a 'Lives' system quite well I thought.

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • quantumsheepquantumsheep Member Posts: 8,188
    Oh, and have a look at Nulo's power and fuel bars on his game 'Human Invasion' - I'd love to know how to do that! :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • FreztinoFreztino Member Posts: 30
    i also got a health bar, in my game iConShooter: http://gamesalad.com/game/play/3852
    in the last level. the way i made it is:
    1. get the image(s) for the bars
    2. Give it the replicate behavior. and set copies to game.[WhatEverYouCalledIt]
    and you can chose the direction and spacing yourself

    Hope it helped

    From freztino =)
  • quantumsheepquantumsheep Member Posts: 8,188
    Thanks Fretz - I'll check it out when I get home :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • Here is another way besides using the replicate.

    Create an actor with a width set to 150. Have the image for it look the same no matter how it is stretched. Constrain the width of the actor to a percentage based on life.

    e.g. If you have 5 max life points, constrain the behavior to 150*#ofLives/5.
  • quantumsheepquantumsheep Member Posts: 8,188
    I'm not sure I fully understand that, but I'll give it a go when I get home - might make more sense if I have GameSalad open in front of me! :)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • JGary321JGary321 Member Posts: 1,246
    I think I will convert my Castle Defense to an HP/MP bar as well. I never thought of doing the constrain image thing. Thanks for the idea.
  • butterbeanbutterbean Member Posts: 4,315
    So If I was wanting to create a health bar that had 3 hits available before the player dies, would I create a separate Actor prototype named "Health Bar", and place constrain attribute as you said, but with what numbers if I only want one life for the player?

    Total newbie so I apologize ^^

    I need detailed instructions too , for example, is there any other attributes that I would want to add to the "Health Bar" prototype?
  • quantumsheepquantumsheep Member Posts: 8,188
    Hey there,

    Firstly, add a variable (integer) called 'Energy' or 'Lives'. In my example I've named Lives 'Energy', which might confuse people - sorry!

    Give this attribute a number. I put in 10.

    Make a graphic that's a square block 32x32 and colour it a single colour.

    Add this to images in GameSalad.

    Create an actor called 'Energy'.

    Attach the image to your actor.

    Now look at this image, which is the attribute for our actor: http://quantumsheep.googlepages.com/energybar.jpg

    In the actor's attributes, I made the width 100 and the height 20 (see image, left hand side). This can be fiddled about with.

    I added a constrain behaviour, as was mentioned in a previous post.

    Have a look at the image again, and you'll see that we constrain the attribute self.size.width first.

    Do this by:
    *pressing the button next to the text box
    *go down to the value that is the name of your actor and click that
    *then click on size*
    *then click on width

    The next box is where we put in the equation as shown in the Gendai Games post earlier.

    Again, access the attribute browser by clicking on the little button next to the text box.

    *In the text box, type 100/ (100 because that's the width of the bar, which we put in the attributes)
    *Click the down pointing arrow button (it's furthest on the right, next to x and the tick)
    *click on 'Game' (first option)
    *click on 'Lives' or 'Energy' (whatever your variable is named)
    *then type /10 - or however many lives you've given your player
    *click the 'tick' button

    Now, place this actor into your scene.

    When your player takes damage, make sure you put in a 'change attribute' behaviour to tell the game that your energy/lives is energy/lives-1

    Now when your player takes damage, the bar will shrink.

    I hope that's helpful. Here's what it looks like in my upcoming game 'Turrets Syndrome'

    http://quantumsheep.googlepages.com/TurretsSyndrome-Level1-example.jpg

    As you can see, I've converted the numerical values for the shields and energy to bars.

    Hope that helps and makes sense!

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • nulonulo Member Posts: 315
    on my human invasion project, the "health bars" are created using an numerical attribute that defines how much life the player has, and an actor that changes its width depending on this numerical attribute.

    Butterbean21 - if you wanted a 3 hit life, then ll you need to do is define the width of your life bar. lets say its 60 pixels wide. then you would make an attribute that says that the players health is "60". then you would make this bar, change its width depending on this number. then you make each hit take away 20 from the players health. this way each hit will take 1/3 of the bar. if you want it to be 100 pixels wide then make each hit take away 34 (this way on the third hit it would go below 0)
    hope that helps
  • butterbeanbutterbean Member Posts: 4,315
    I'm understanding the concepts, but having a hard time when going into GameSalad and putting in these attributes into my Actor etc.

    Can you tell me in detail how you did this?

    For example:

    I created an actor prototype and named it "HealthBar", changed the size to 75 width, and 20 height, so 1/3 of the bar is 25 life

    Inside that actor prototype, what attributes or rules would you add into it?

    Would you also create a global game attribute and call it "playerhealth" or "healthbar" IF so, would it be integer, and number 75 for me given the width of the health bar? OR would it only be 3?

    Thank you so much, again, complete newbie here, sorry! ^^ Thank you for your patience :)
  • butterbeanbutterbean Member Posts: 4,315
    Sorry Quantum sheep, I didn't see your post above, THANK YOU that is so detailed and helpful for total newbies like myself!

    Are you available via ichat if I ever have more questions?

    I am learning... slowly! Thanks again ^^ :)
  • ktfrightktfright Member Posts: 964
    Dang............You guys are good!!!!
  • butterbeanbutterbean Member Posts: 4,315
    Quantum Sheep, when you said at the end to place a change attribute so that the lives is energy bar goes down by one, do I place that change attribute within the player prototype in the game, known as the main character?

    Also, do I create another global game attribute that says player lives and is integer in addition to player health?

    Thank you :)
  • nulonulo Member Posts: 315
    alright!
    1 - create an attribute and set it to 75 by default (75 because the width of your bar is 75)(lets call it "life.attribute").
    2 - create a rule inside the bar that checks if the attribute is different then 75
    3 - inside the rule create a timer that every x seconds it changes the bars self.size.width to the "life.attribute"
    4 - when your monsters hit your player make it take away from the "life.attribute" (if you make it take 25, then its 1/3 so it all depends on you.)
    hope this helps
  • JGary321JGary321 Member Posts: 1,246
    Hey Quantum/Nulo you may wanna add this to the wiki =). Very helpful stuff.
  • butterbeanbutterbean Member Posts: 4,315
    Thanks Nulo! Just wanna verify a few details on that so when I get home, I can go right to it :)

    1) SO you create a global game attribute as integer, and set it to default 75 correct? (the one you said to name life.attribute)

    2) When you say create a rule inside the bar, you mean the actor prototype health bar correct? So when I create a Rule, what boxes would I click on?

    3) And then the Timer box inside the rule, how many seconds would you recommend it check to see if the bars self.size.width changes according to life attribute?

    4) When you say "monsters hit player" and it takes away 25 points (1/3 life), where would I create this attribute, would it still be within the health bar prototype?

    * What do I need to create within the player1 (main actor) that would correspond with these rules regarding the health bar?

    That's where I'm having difficulty is knowing where to put what rules, such as what rules go in the health bar versus what rules go to the primary player (main actor)
  • butterbeanbutterbean Member Posts: 4,315
    By the way, Quantum or Nulo, if you have ichat or email, can you let me know as I will probably need more assistance :) if not I understand :)
  • quantumsheepquantumsheep Member Posts: 8,188
    Butterbean - the way I'd do it is have the constrictions on the health bar actor, and the 'player takes damage' stuff on the main actor.

    Hope that helps!

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • zombotszombots Member Posts: 186
    thanks quantumsheep, this was a huge help
  • JGary321JGary321 Member Posts: 1,246
    QS I added this to the wiki. Gave credits to you of course =p
  • JGary321JGary321 Member Posts: 1,246
    Take a look at the new Bars 101 wiki page. It shows an expanding/contracting bars, but with a set max size, so the bars don't get HUGE with a lot of lives.

    http://gamesalad.com/wiki/bars_101

    JGary
Sign In or Register to comment.