Health Bar: add/subtract size to the left or right?
xacto
Member Posts: 146
I am creating a health bar (a red box PNG) and I want it to shrink from the left.
If I set up code to adjust the SIZE of a graphic (subtract width), it will reduce from the CENTER. Is there a way to adjust the center point so I am able to grow from left or right?
The only other way I can think about doing this is spawning multiple PNG boxes that would touch and I would destroy them when I need to reduce. (This seems like a lot of work)
Any other way around this?
If I set up code to adjust the SIZE of a graphic (subtract width), it will reduce from the CENTER. Is there a way to adjust the center point so I am able to grow from left or right?
The only other way I can think about doing this is spawning multiple PNG boxes that would touch and I would destroy them when I need to reduce. (This seems like a lot of work)
Any other way around this?
Comments
Second: Find the center of the actor. Its always half of the width.
Now constrain the position of the actor relative to the right border and the width.
Constrain Attribute: self.Position.X = 470 - self.Size.Width/2
Not sure if I am following you. My graphic I am using is a 8x8 white square that will. Are you saying I should constrain the X attribute to "4-self.size.width/2"?
@tshirtbrooth, I tired but for some reason did not work - not sure why.
Another note.... this is really a timer bar, the time may be different each time because of powerups.
You could just constrain self.player.X to 470-(game.Time/1)
See both methods here:
http://gamesalad.com/game/play/25501
Thanks for the code.... it now makes sense!!!!
That needs to be in a wiki.