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

Author Topic: function repeating on single keypress  (Read 2203 times)

0 Members and 1 Guest are viewing this topic.

mongrol

  • Newbie
  • *
  • Posts: 29
    • View Profile
function repeating on single keypress
« on: July 11, 2009, 01:24:04 pm »
Hi folks,
In my turn based game I have a key A that executes an attack function. he function seems to endlessly repeat until the target runs out of health effectively creating a one shot kill situation. ;)

If I insert a std::cout << ""; statement in the function then it only executes once. Or it's executing a lot slower.

Any clues what's going on here and how to prevent it. Disabling keyrepeat on the window doesn't help.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
function repeating on single keypress
« Reply #1 on: July 11, 2009, 04:07:55 pm »
std::cout is slow ( mainly with Windows ) so your FPS reduce and your attack function is called less often.

How do you call it ? I mean, do you test with sf::Input if the key is down ? Or do you use sf::Event ?

If you're using sf::Input you need a clock to turn off temporarily the call of the function.

If you're using sf::Event, disabling key repeat should be enough.
SFML / OS X developer

mongrol

  • Newbie
  • *
  • Posts: 29
    • View Profile
function repeating on single keypress
« Reply #2 on: July 12, 2009, 03:54:05 am »
My fault. I wasn't returning 0 from my event function when nothing was being pressed so it was returning the last event code instead. All fixed.

Thanks,

 

anything