constraining a health bar directly in the middle with changing width

digitalzerodigitalzero Member, BASIC Posts: 639

so im having trouble constraining my health bar... but heres the secret though;

i have an actor that changes the game.boss health and its size is whatever the boss health is period (its a real attribute because some of my guns take away .5) now the health screen is right on the field directly in the middle so its position x is 240 and since the size will change depending upon which boss youre playing i am in need of a formula that will constrain it each and every time so that it does not shrink and is able to keep the health bar actor in the middle... i have tried to constrain it a couple of ways... which include

constraining it 240-(self.size.width)/2

which makes sense in my head but im still not getting it

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If self.Position.X is 240, then the actor is centered at x=240. If self.Size.Width increases or decreases, it will do so equally from each side of the center. There's nothing tricky about this... just constrain self.Size.Width to game.health. Use a constant as needed (e.g. game.health*10).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639

    @tatiang I'm more talking about the position of the healthbar and not having the health bar shrink and have it shrink on one side

  • digitalzerodigitalzero Member, BASIC Posts: 639

    I'm going off of the tshirtbooth tutorial

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I think you better post a screenshot/sketch at this point. It sounded like you wanted to constrain a health bar to the middle of its width but now it sounds like you want it left-justified, so I'm not sure...

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639
    edited March 2015

    let me try to do a better job of explaining this...

    so i have the actor set in the middle of the scene... dead center...

    the length of the health bar changes depending upon which boss you are facing... (its also constrained)

    when you hit the boss the energy bar shrinks however when it shrinks it does it from both sides...

    i always want the health bar to be in the middle no matter if the health is 100 or 1000...

    and i want the bar to not shrink from the middle but from the left side...

    a great example would be an rpg game how the health bar always shrinks to the left no matter what the maximum hp is...

    did that explain things a little better? @tatiang

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @digitalzero said:

    did that explain things a little better? tatiang

    Uh... it's not my night! :#

    i always want the health bar to be in the middle no matter if the health is 100 or 1000...

    and i want the bar to not shrink from the middle but from the left side...

    How can you have a bar that is always in the middle yet shrinks from the left side?

    Let's take this example:

    Bar "A" shows full health at 1000. Bar "B" shows 750 health where the position of the actor is always centered. The bar MUST appear to shrink from both sides in this case. Bar "C" shows 750 health where the width is shrinking from the left. Notice that the bar is not centered any longer.

    Are either of those what you're wanting?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639

    @tatiang C IS EXACTLY WHAT IM LOOKING FOR... but the health bar would be shrinking from the other side... when i constrain its position i change the health for another boss the health bar is not in the center... i just want it to be right in the middle all the time but shrink like the example c (but from the other side of course)

    so my code was looking like this constrain self.position.x to 240-(self.size.width)/2...

    however that does not work whatsoever

  • digitalzerodigitalzero Member, BASIC Posts: 639

    @tatiang this is great! thanks for the example... sometimes im horrible at explaining things -__-

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I'm glad C is what you're looking for because you're still saying conflicting things. But I'm going to let that go because it's just arguing for the sake of arguing... let's move on to solutions. :)

    Here's a demo.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    By the way, if you either position the actor at x=240 or add a Change Attribute self.Position.X to 240 at the top of the actor's rule list (outside of any rule), it will left-justify at x=240.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639

    THANKS SO MUCH @tatiang let me tell you what i ended up doing though... i ended up making a game attribute that is labeled boss icon x... on the boss icon it spawns at the end of the health bar everytime so it will calculate that position because on the actor i have one rule placed change attribute game.boss icon x to self.postition.x... now. on the boss health icon i have constrain attribute self position x to game boss icon x + self width/2 .... it works as far as it the placement but its still shrinks..

  • digitalzerodigitalzero Member, BASIC Posts: 639

    OH WAIT @tatiang i came up with a GREAT ANALOGY! so picture a word document but having the alignment centered!!!! THATS what im trying to do but the bar moves over accordingly and shrinks from the x its at... so it wont always shrink from 240 but when it shrinks i want it centered... make sense?

  • digitalzerodigitalzero Member, BASIC Posts: 639

    another analogy this actually may be what you need... so the 1 pixel health bars x is set at 240 now if i were to stretch that health bar to 1000 it will stretch both sides but NOW... i need it to stretch to the left... sure the x is still going to be the same because its going to be in the middle but the end of the actors x is going to be in a different place and i would need it to shrink from there

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2015

    If you look at the image posted above, "B" is centered (using the vertical line as the center of the scene) but shrinks from both sides while "C" is right-justified but shrinks from the left. As I said before, you can't left-justify (or right-justify) something that is shrinking and have it still be centered.

    Anyway, do you have what you need now? I didn't really follow this:

    on the boss icon it spawns at the end of the health bar everytime so it will calculate that position because on the actor i have one rule placed change attribute game.boss icon x to self.postition.x... now. on the boss health icon i have constrain attribute self position x to game boss icon x + self width/2 .... it works as far as it the placement but its still shrinks..

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639
    edited March 2015

    ok i just had to give you a picture and hopefully this explains what im talking about... i had to give in and run my good ol photoshop lol here you are hopefully this explains

  • digitalzerodigitalzero Member, BASIC Posts: 639

    there we are... so @tatiang the red lines show the boss hp the lighter red is if the energy is taken a little... on the left you will see three grey lines... thats where i want it to shrink for each actor... just like you had in your example c... the middle line just shows the middle of the scene

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Okay! We're in agreement. :)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639

    You get what I'm talking about now @tatiang ?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Yep.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • digitalzerodigitalzero Member, BASIC Posts: 639

    Do you know how i would be able to do that?

  • ArmellineArmelline Member, PRO Posts: 5,369
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2015

    @digitalzero said:
    Do you know how i would be able to do that?

    You could try my demo from two days ago. :p

    http://forums.gamesalad.com/discussion/comment/528732/#Comment_528732

    Unlike @Armelline's superior demo, no monsters were harmed in the making of mine.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,369

    @tatiang said:
    You could try my demo from two days ago. :p

    If I understand things correctly, he just wanted your demo, but with the bar fixed to the centre of the screen/an actor. The change to do that is super-simple, though, so my demo is more flash than additional substance :P

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @Armelline It could be lack of sleep but I've been insisting that you can't left-justify a bar and center it at the same time. I guess I get it now... center it to begin with and then left-justify it as it shrinks.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.