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

Author Topic: sf::Joystick::getAxisPosition is not recording Hold!  (Read 1270 times)

0 Members and 1 Guest are viewing this topic.

VileX1337

  • Newbie
  • *
  • Posts: 3
    • View Profile
sf::Joystick::getAxisPosition is not recording Hold!
« on: November 15, 2012, 03:15:36 am »
I am trying to test out the entirety of the window module to get a hang of it. As part of that project im trying to change the glClearColor on every frame depending on the position of the axis! Problem is when i first move the analogue stick it works just fine! Now when i try to hold the analogue stick  to the left it only works for the first frame then it fails the if test! All the code besides the axis part work. I am using the Xbox 360 Controller for PC if that helps. Code below:

   
        Event event;

        float R = 0.0f;
        float G = 0.0f;
        float B = 0.0f;

        while (window.isOpen())
        {      
        while (window.pollEvent(event))
        {
            if (event.type == Event::Closed)
            {
                window.close();
            }
            else if (event.type == Event::Resized)
            {
                glViewport(0, 0, event.size.width, event.size.height);
                        }
                        else if (Keyboard::isKeyPressed(Keyboard::Escape))
                        {
                                window.close();
                        }
                        else if (Joystick::isButtonPressed(0, 0))
                        {
                                window.close();
                        }
                        else if(Joystick::getAxisPosition(0, Joystick::X) > 50)
                        {
                                R = R + 0.01f;
                                G = R + 0.01f;
                                B = R + 0.01f;
                        }
                        else if(Joystick::getAxisPosition(0, Joystick::X) < -50)
                        {
                                R = R - 0.01f;
                                G = R - 0.01f;
                                B = R - 0.01f;
                        }
                }

        // clear the buffers
                glClearColor(R, G, B, 0.0f);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // end the current frame (internally swaps the front and back buffers)
        window.display();
    }

Thanks in advance~!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf::Joystick::getAxisPosition is not recording Hold!
« Reply #1 on: November 15, 2012, 07:54:55 am »
Your code is inside the event loop. So it is executed only when there's an event. And if you do nothing, no event is triggered of course.
Laurent Gomila - SFML developer

VileX1337

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Joystick::getAxisPosition is not recording Hold!
« Reply #2 on: November 15, 2012, 02:18:23 pm »
I need the code to be executed within the main loop (Shown Above) were would I then properly okace the checker then?

VileX1337

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: sf::Joystick::getAxisPosition is not recording Hold!
« Reply #3 on: November 15, 2012, 02:21:32 pm »
I figured it out thank you!