Displaying Health Bars
butterbean
Member Posts: 4,315
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
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.
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
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
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
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.
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
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?
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
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
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
Are you available via ichat if I ever have more questions?
I am learning... slowly! Thanks again ^^
Also, do I create another global game attribute that says player lives and is integer in addition to player health?
Thank you
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
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)
Hope that helps!
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
http://gamesalad.com/wiki/bars_101
JGary