My health bar colour formula is doing my nut...
stuicy
Member Posts: 6
Hey guys, noob is here again.
I have a health bar, game.health is the game attribute and max health is 10.
I made the health bar all nice, and set two rules to change the colour as the health decreases.
1) 6 to 10 health, when attribute game.health is greater than or equal to 6, change self.blue to 0, change self.green to 1, change self.red to (10-game.health)/5
2) 1 to 5 health, when attribute game.health is less than or equal to 5, change self.blue to 0, change self.red to 1, change self.green to game.health/5
Now this should work and give a smooth colour transition from 10 down to 1 health... or am I missing something?
Hope you can help, thanks.
Stu
I have a health bar, game.health is the game attribute and max health is 10.
I made the health bar all nice, and set two rules to change the colour as the health decreases.
1) 6 to 10 health, when attribute game.health is greater than or equal to 6, change self.blue to 0, change self.green to 1, change self.red to (10-game.health)/5
2) 1 to 5 health, when attribute game.health is less than or equal to 5, change self.blue to 0, change self.red to 1, change self.green to game.health/5
Now this should work and give a smooth colour transition from 10 down to 1 health... or am I missing something?
Hope you can help, thanks.
Stu
Best Answers
-
gyroscope I am here.Posts: 6,598
@stuicy
Hi Stu, why not make it simpler and have it so green and red fade in an out over the full amount? What I mean is:
Make a boolean as a switch; make it true just after your Rule change attribute game.health, (which you surely have), so:
Change attribute game.health to game.health-1
Change attribute Switch to true
Make your Rule:
When Switch is true
----blue is already set to 0, red to 0 and green to 1
Change attribute self.Color.Red to self.Color.Red + (1 -game.health/10)
Change attribute self.Color.Green to self.Color.Green - (1-game.health/10)
Change attribute Switch to false
This is off the top of my head but should work out (providing you'll want a gradual fade in and out, that is...)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
Glad it worked out for you! And to answer your question: the reason for the boolean "switch" is to to trigger the Rules into action each time game.health changes, otherwise it would only happen once. :-)""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
Hi Stu, try adding the Interpolate into the same Rule:
Change attribute game.health to game.health-1
Change attribute Switch to true
Make your Rule:
When Switch is true
Change attribute self.Color.Red to self.Color.Red + (1 -game.health/10)
Change attribute self.Color.Green to self.Color.Green - (1-game.health/10)
Interpolate scene.Background.Bar.Size.Width to scene.Background.Bar.Size.Width-10
Time:0.2 seconds --- or whatever you want
Change attribute Switch to falseSorry again for being a total noob, I'll get the hang of it soon!
No worries, really, no rush! :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Answers
I left it as two rules because I wanted yellow to be the halfway point at 5 health, which needs red and green to be at 1. So one rule 6-10 to bring the red up to 1, then a second rule from 1-5 to take the green down to 0.
Now just so I get it straight in my head, why did it only work when there was a second attribute - or switch as you said - added to the mix? Why didn't it work as it was?
I only ask because it's confusing me and I want to be able to understand as much as I can so I don't have to ask silly questions in here all the time!
Thanks again, worked a treat!
Stu
But it won't work for me... my attribute game.health is decreased when two actors touch by changing attribute game.health to game.health-1. But when I use interpolate instead of change attribute, the health bar doesn't just decrease by 1 anymore, it drains completely.
Any idea where I'm going wrong? Perhaps I need to use the interpolate with the bar width instead, but that is constrained to game.health*10 (game.health starts at 10 and my bar is 100 pixels wide).
Help!
Stu
Works like a dream, thanks.