Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Cooldown time visualization  (Read 2799 times)

0 Members and 1 Guest are viewing this topic.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Cooldown time visualization
« on: August 01, 2012, 01:39:58 am »
Hi there!  ;)

In my game, the player can hit the enemy, and then he must wait for a "cooldown" time to hit again. I´m trying to display a graphic (like a clock) to represent the elapsed time.

I have the constant CD time and a sf::Clock to check the elapsed time since de CD begins
const sf::Time cooldownTime = sf::seconds (0.7f);
sf::Clock elapsedCDTime;
 

I have the graphic shapes
sf::CircleShape circle (30.0f); // The "clock" shape

circle.setFillColor (sf::Color::Transparent);
circle.setOutlineColor (sf::Color::White);
circle.setOutlineThickness (4.0f);

sf::RectangleShape needle (sf::Vector2f (40.0f, 4.0f)); // The clock "needle"
needle.setFillColor (sf::Color::White);
needle.setRotation (90.0f);
 

Now, I want the "needle" to start rotating from 90 deg. to give a full turn, clockwise. How can I calculate the needle rotation, based on the elapsed time?

Thanks for your time, and sorry for the bad english  :P
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Cooldown time visualization
« Reply #1 on: August 01, 2012, 02:55:09 am »
It should be something like this.

// time passed so far, divided by the total time of the cooldown
float rotation = elapsedCDTime.getElapsedTime() / cooldownTime;
rotation *= 360; //constant, this normalises the value to degrees
needle.setRotation (rotation);

With some example numbers, for a 5 second cooldown. If 4 seconds have passed, the above maths results in 288 degrees. Which sounds about right.

convert the sf::Time variables into whichever time unit you prefer and it should work fine.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Cooldown time visualization
« Reply #2 on: August 02, 2012, 12:54:49 am »
Thanks thePyro_13
It´s working  :)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

 

anything