Health Bar: add/subtract size to the left or right?

xactoxacto Member Posts: 146
edited November -1 in Tech Support
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?

Comments

  • Fafnir312Fafnir312 Member Posts: 161
    Hmmm... I don't know how to offset the center (if that's even possible) but you could shrink the actor and then offset it the same amount it shrinks. Then it'd look like it's staying in the same place and shrinking.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    First: Look at what is always constant. The right edge of the health bar. Lets say its at x=470.
    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
  • xactoxacto Member Posts: 146
    @CodeMonkey

    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.
  • ShanestaShanesta Member Posts: 63
    If you have a variable for Time
    You could just constrain self.player.X to 470-(game.Time/1)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    You can also try with the Replicate behavior.

    See both methods here:
    http://gamesalad.com/game/play/25501
  • xactoxacto Member Posts: 146
    CodeMonky

    Thanks for the code.... it now makes sense!!!!

    That needs to be in a wiki. :)
Sign In or Register to comment.