percent progress bar

myu699myu699 Member Posts: 96

Hi, so I am creating a running game(not endless) and I have a a variable that records the percent ran(the max is 100). So
I have a progress bar that is 270 pixels wide. I have made my variable equal self.size.width(of the progress bar). then constrain self.position.x = 27+(self.size.width)/2. So the problem is that I cant figure out how to show the percentage in a progress bar so that when it is 100% the progress bar is 270 pixels wide. Please dont post a file(not enough storage) but rather a screenshot,video, or type it. Thanks. Please reply in the next 10 days because I have a free trial(had account for 2 years, but not paid) and want to finish my game(worked on for year). Thank you so much.

Comments

  • ArmellineArmelline Member, PRO Posts: 5,364

    (100/max value)*current value

    I assume that's what's you're meaning?

  • myu699myu699 Member Posts: 96

    what I mean is that I have a progress bar that is meant to be 270 pixels wide when it is 100% progress, but I cant figure out how to do it

  • tintrantintran Member Posts: 453

    your_percent/100 * 270
    so that when your_percent is 100 you get 270

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

    I believe you'd want -- and chances are Armelline is about to post something way more instructive! -- (current value/max value)*max width

    So if you're using game.score to determine the width of the progress bar and you have a maximum score of 500, you would constrain self.size.Width to (game.score/500)*270.

    The idea is that the current value divided by the maximum value results in a percentage (0% to 100% or equivalently, 0 to 1) and when you multiply that by the maximum width, in this case 270, you get a value from 0 to 270.

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

  • myu699myu699 Member Posts: 96

    ok, but I want to make sure that the progress bar begins on the left side and moves to the right. A lot of the ways I found only create a progress bar the grows on each side, I want it to only grow(increasse width) from one side. I found this by @RabidParrot

    Take player's x position.

    Display Text.

    roundTo(( self.Position.X / scene.Size.Width )*100,0).."%"

    but the problem is this is for displaying text. This is what I have used for finding percent. But I cant convert it into a progress bar.
    I have used this for the progress bar

    self.size.width=game.score
    self.postition.x= 27+((self.size.width)/2)

    but I dont know how to make it so it is compatible with a percent as game.score

    I add 27 for padding

  • tintrantintran Member Posts: 453

    I have used this for the progress bar

    self.size.width=game.score
    self.postition.x= 27+((self.size.width)/2)

    if you want the width to be maximum 270 at 100%
    you set

    self.size.width = (game.score/max_score) * 270
    self.postition.x= 27+((self.size.width)/2)

    you must know what the max_score is right?

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    You could also use the method in the tutorial below, this uses the Replicate Behavior and with that you can choose which direction you want your bar to grow/shrink from without constraints.

  • Thunder_ChildThunder_Child Member Posts: 2,343

    Hmm. Seems a lot of ways to do it. 270px/100% is 2.7px/1%

    So it seems reasonable if your runner has to run say.....6000px total to get to 100%.....that's 60px every 1%....have an integer you save every 60px of self.start to self.start+1

    Then like a high score have another integer to save if greater than last "percent" change percent to current percent.

    Then when every percent is greater than previous percent...change attribute progress bar to progress bar position +2.7px....

    When progress bar is equal to or greater than 270px spawn "you win" or whatever...

    Does this sound to long way around? I don't know those good math skills so I have to Boolean and save "scores".

    This is the direction I would be trying if I didn't know math.

    Hope it does t look stupid. Lol

Sign In or Register to comment.