playMaker

Author Topic: Make bar go from 1 side to another? (Ex:HP bar)  (Read 355 times)

PleaseHelpMe

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Make bar go from 1 side to another? (Ex:HP bar)
« on: November 05, 2018, 01:18:01 AM »
How do I make it so based on an integer amount 0 = no bar and 100=full bar and everything in between. To where the bar will increase and decrease based on the integer number.

Without having to do an action for each number from 0 to 100?

Thore

  • Sr. Member
  • ****
  • Posts: 305
    • View Profile
Re: Make bar go from 1 side to another? (Ex:HP bar)
« Reply #1 on: November 05, 2018, 04:36:29 AM »
When you approach a problem like this, first try out “dry” what needs to happen. For example, you could make a sprite with the bar. Set the pivot to the left side, then scale the x value and see what happens. You can then play around in the editor and get a feel for the values you would need for x scale. The bar could also be setup to be scale 100 right away (or done with a mesh or with an SVG sprite etc). If you cannot use the pivot, you get the same result by simply using an empty game object. Add a gizmo so you can see it, and then put as child the bar object underneath so that the empty parent is where the pivot is (i.e. left). When you scale the parent x, the bar should shrink and grow accordingly.

Next, you can start building the FSM that does the “slider pulling” in an automatic fashion, where you need to correspond the HP value to the x scale, i.e. 50 points is x scale 0.5 etc. To do this, use actions like float remap. You probably also need to convert the int to a float to drive the x scale.

Hope that helps,

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 989
    • View Profile
    • Fat Pug Studio
Re: Make bar go from 1 side to another? (Ex:HP bar)
« Reply #2 on: November 05, 2018, 10:26:03 AM »
That's a great way. If you find it too complicated, you can always put a blank sprite that will "hide" the portion of the health bar by utilizing sprite mask and move itself to appropriate positions.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Re: Make bar go from 1 side to another? (Ex:HP bar)
« Reply #3 on: November 05, 2018, 02:17:44 PM »
Hi.
You can also use the Ui Slider.

On the 'slider component' you can set then min/max manually but you can also do this with an action (useful if health dynamically grows)

Also you can set it to whole numbers

Then you can set the value with an action to manipulate the slider (health bar)
If your value is an int (and you are using PlayMaker 1.9+) then you can select the variable by selecting convert and select your int variable.

In the action window search for 'slider' to see some of the other actions
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14387
  • Official Playmaker Support
    • View Profile
Re: Make bar go from 1 side to another? (Ex:HP bar)
« Reply #4 on: November 22, 2018, 01:06:45 AM »
Hi,

 use the anchor max x for that. I alwasy do that.

 have a ui element stretching out fully on its width, and then use SetAnchorMax and specificlaly just the x component, it ranges from 0 to 1 and will give you a nice generic filling UI rect.

Bye,

 Jean