Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

Filling a bar using time


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 BaneTrapper   Members   -  Reputation: 645

Like
0Likes
Like

Posted 26 October 2012 - 08:23 AM

Hello.
I am unaware how to do this one.
What i am trying to do is make a "Round" system whereby there is a bar(96pixels long) and a timer(5000 milliseconds) and i have no idea how to know how much to fill it. So it looks like its filling per loop up until 5 sec passed when it should be full.
int Max size = 96;
int RoundDelayAmount = 5000;
int RoundAmountTime = 0;
RoundAmountTime += Timer.restart().аsMiliseconds() /* restart() will return a time elsped from last restart() call */ /* This is called each loop */
int Xsize = ??? ;
setSize(  Xsize, 10.f) // Takes "int x, int y" arguments

Or if you don't like this, how would you do this?

Edited by BaneTrapper, 26 October 2012 - 08:25 AM.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


Sponsor:

#2 Waterlimon   Members   -  Reputation: 1138

Like
4Likes
Like

Posted 26 October 2012 - 08:29 AM

If you have a max time (bar full when this amount of time passed) and current time passed, you can get the ratio of full and empty bar sections by dividing TimePassed by MaxTime, which you then convert to the correct units by multiplying by the bar lenght.

So, i believe Xsize=(RoundAmountTime / RoundDelayAmount) * MaxSize;
The lack of awesome free resource gathering building sandbox games capable of running an user made 8 bit computer in the world disturbs me.

#3 BaneTrapper   Members   -  Reputation: 645

Like
0Likes
Like

Posted 26 October 2012 - 10:13 AM

If you have a max time (bar full when this amount of time passed) and current time passed, you can get the ratio of full and empty bar sections by dividing TimePassed by MaxTime, which you then convert to the correct units by multiplying by the bar lenght.

So, i believe Xsize=(RoundAmountTime / RoundDelayAmount) * MaxSize;


Thanks this works fine.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/


#4 proanim   Members   -  Reputation: 398

Like
0Likes
Like

Posted 26 October 2012 - 12:10 PM

This is 'easy' thing to do you already have max amount so probably the best thing to do is use a varable that will be incremented every 1 sec or so, when the value is incremented you expand your progress bar by some amount, when value that is beign incremented is equal to max the progress bar is full. Entire thing can be done in more or less one for loop.

#5 incertia   Crossbones+   -  Reputation: 525

Like
0Likes
Like

Posted 26 October 2012 - 01:10 PM

So, i believe Xsize=(RoundAmountTime / RoundDelayAmount) * MaxSize;


You could also cast them to floats... but since RoundDelayAmount is 5000, it wouldn't really matter lol.
Current project here

#6 BaneTrapper   Members   -  Reputation: 645

Like
0Likes
Like

Posted 29 October 2012 - 04:02 PM


So, i believe Xsize=(RoundAmountTime / RoundDelayAmount) * MaxSize;


You could also cast them to floats... but since RoundDelayAmount is 5000, it wouldn't really matter lol.


Actually it mothers since it improves accuracy. And i do cast them to floats.

Current projects:
The Wanderer, 2d turn based rpg style game

www.gamedev.net/topic/641117-check-up-the-wanderer/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS