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

Author Topic: mouse button press only once  (Read 3192 times)

0 Members and 1 Guest are viewing this topic.

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
mouse button press only once
« on: July 09, 2017, 05:49:18 am »
hi...I think I have asked more than 2 question in this forum since yesterday...
anyways...
I want to have it so my mouse button received input is not received when it is pressed continuously
I know you can do it with event...but the code where the mouse input received is in another file
so I tried this code...
Code: [Select]
     while (1)
    {
        if ( (sf::Mouse::isButtonPressed(sf::Mouse::Left)) && (!pressed) )
        {
            std::cout << "haha" << i++ << " " << pressed << std::endl;
            pressed = true;
            std::cout << pressed;
            continue;
        }
        pressed = false;
    }
even If I pressed the left mouse button...it didn't continue..I wonder why

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: mouse button press only once
« Reply #1 on: July 09, 2017, 05:57:31 am »
nvm I see the problem...

Flaze07

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: mouse button press only once
« Reply #2 on: July 09, 2017, 06:00:08 am »
just found a fix  :D :D ;D

Code: [Select]
     while (1)
    {
        if ((sf::Mouse::isButtonPressed(sf::Mouse::Left)))
        {
            if (pressed) continue;
            else
            {
                std::cout << "haha" << i++ << " " << pressed << std::endl;
                pressed = true;
                std::cout << pressed;
            }
            continue;
        }
        pressed = false;
    }

funny how I realized it after looking at my own thread

 

anything