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

Author Topic: Function do not works  (Read 1987 times)

0 Members and 1 Guest are viewing this topic.

game_maker

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • Email
Function do not works
« on: January 27, 2013, 11:43:53 pm »
Hi!

I am using this code:

sf::RenderWindow window(sf::VideoMode(800, 600, 32), "");
window.setKeyRepeatEnabled(false);

But, when I check if a key was pressed, the event runs (is triggered) 2 times.

To check the key, I use:

void GameManager::Update(sf::Event event)
{
ReleasedKey=sf::Keyboard::KeyCount; //basically "NoKey"
PressedKey =sf::Keyboard::KeyCount; //bascically "No Key"

switch (event.type)
{
    case sf::Event::KeyReleased: ReleasedKey=event.key.code;
    case sf::Event::KeyPressed: PressedKey=event.key.code;
default: break;
}

}

And:

GameManager game;
...
while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
            game.Update(event);

            if (game.keyboard_check_pressed(sf::Keyboard::A))
                std::cout << 'A' << endl;
        }

I can not find the error... Please help me.

Note: I use Windows 7, Code::Blocks, MinGW, SFML 2.0.
« Last Edit: January 27, 2013, 11:47:32 pm by game_maker »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Function do not works
« Reply #1 on: January 27, 2013, 11:49:25 pm »
Please read this then... ;)

What exact SFML version, what OS, what hardware, etc...

My blind guess would be Linux and this thread (yes the search function works even on your end). :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Function do not works
« Reply #2 on: January 27, 2013, 11:59:18 pm »
My blind guess (since you're using win7 and not linux :D): unless you know what you're doing, use break in your switch cases.

Here for one key pressed (and released) you go in your second case twice, once when the key is pressed, another one when the key is released.

game_maker

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
    • Email
Re: Function do not works
« Reply #3 on: January 27, 2013, 11:59:51 pm »
Quote
Please read this then...
OK...

Quote
What exact SFML version, what OS, what hardware, etc...
OK...

Quote
My blind guess would be Linux
Wrong.

Quote
and this thread (yes the search function works even on your end).
I saw this topic and I imagined that someone would tell him.
And I do not like (I hate) this internal search engine.
I always 'google' this way: site:sfml-dev.org 'my keywords here'.
I 'googled' before asking.
------------------------------------------------------------
Edited:

Quote
use break in your switch cases
Solved.

Thanks!
---------------------------
eXpl0it3r, I admire you so much. Sorry for anything.

Thanks.
« Last Edit: January 28, 2013, 12:05:23 am by game_maker »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Function do not works
« Reply #4 on: January 28, 2013, 02:21:28 am »
And I do not like (I hate) this internal search engine.
Yeah, I wish it was better and specially that the MySQL wouldn't disconnect randomly when doing a full search... :-\

eXpl0it3r, I admire you so much. Sorry for anything.
;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything