SFML community forums

Bindings - other languages => Python => Topic started by: Veritas on June 08, 2014, 10:15:15 pm

Title: sf.Keyboard.is_key_pressed() expensive?
Post by: Veritas on June 08, 2014, 10:15:15 pm
I was wondering, is sf.Keyboard.is_key_pressed() expensive?
My tests lag considerably when there are 70+ controllable objects at a time (about 300 calls).
The profiler showed that 90% of the time was spent in the is_key_pressed() function so either I am doing something wrong or the function is expensive (after many calls that is).
Title: Re: sf.Keyboard.is_key_pressed() expensive?
Post by: saluk on August 07, 2014, 09:40:01 pm
One question: Why do you have 70 objects checking for keypresses? What kind of game do you control 70 objects at a time?

If you really need to have this many objects controllable at once, you could optimize by saving the result of is_key_pressed each frame and just checking the variable.
Title: Re: sf.Keyboard.is_key_pressed() expensive?
Post by: Hapax on August 07, 2014, 09:52:40 pm
I can't understand why, in one cycle, you'd want to call isKeyPressed 300 times as it's highly unlikely that the keyboard has that many keys.