SFML community forums

Help => General => Topic started by: MarbleXeno on July 18, 2020, 01:54:57 pm

Title: Idea for sf::Keyboard
Post by: MarbleXeno on July 18, 2020, 01:54:57 pm
Hello, I'm currently working on a dev module for my game that I'm creating for fun (this is a project only for me, i wan't to just learn C++ and SFML) and i have a problem with sf::Keyboard, so basically i wan't to display a dev values (like delta time) - when a player clicks F5 the value appears (so the function is just called there) and when the player clicks f5 again the values ​​disappears, how can i do that?

F5 = DeltaTime appears on the screen.
F5 again = DeltaTime disappears.

PS: Dev module i have already created.
Title: Re: Idea for sf::Keyboard
Post by: Laurent on July 18, 2020, 03:04:17 pm
https://www.sfml-dev.org/tutorials/2.5/window-events.php#the-keypressed-and-keyreleased-events
Title: Re: Idea for sf::Keyboard
Post by: MarbleXeno on July 18, 2020, 03:23:20 pm
I know that I need to use KeyPressed and Released but I don't know how I can do that, I have DevMode class with methods like "displayDeltaTime" and I have also draw method. I don't know how to make text stay on click and disappears after second click. I know about KeyPressed and KeyReleased. That's my problem.
Title: Re: Idea for sf::Keyboard
Post by: Laurent on July 18, 2020, 04:58:58 pm
bool showDeltaTime = false;

// on keypressed event...
showDeltaTime = !showDeltaTime;

// at draw time
if (showDeltaTime)
    DevMode.displayDeltaTime();
Title: Re: Idea for sf::Keyboard
Post by: MarbleXeno on July 18, 2020, 07:59:43 pm
Thank you very much!