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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kudely

Pages: [1]
1
DotNet / Re: Issue using Joystick static methods
« on: January 08, 2015, 04:46:56 am »
Was this issue ever resolved?

2
DotNet / Re: Issue using Joystick static methods
« on: November 10, 2014, 03:05:10 pm »
I use version 2.1.

3
DotNet / Re: Issue using Joystick static methods
« on: November 10, 2014, 12:11:46 am »
Here's an example:

class Program
    {
        private static uint _joystickId;
        private static bool _buttonPressed;

        public static void Main(string[] args)
        {
            RenderWindow window = window = new RenderWindow(new VideoMode(800, 640), "Test");
            window.JoystickButtonPressed += OnJoystickButtonPressed;

            while (window.IsOpen())
            {
                window.DispatchEvents();
                if (_buttonPressed)
                {
                    Update();
                }
                window.Clear(Color.Black);
                window.Display();
            }
        }

        private static void OnJoystickButtonPressed(object sender, JoystickButtonEventArgs e)
        {
            // Once we press a button, set the joystick ID
            _joystickId = e.JoystickId;
            _buttonPressed = true;
        }

        private static void Update()
        {
            // Check to see if the joystick that was last used is connected
            if (Joystick.IsConnected(_joystickId))
            {
                Debug.WriteLine("Controller is connected.");
            }
            else
            {
                Debug.WriteLine("Controller is not connected.");
            }
        }
    }
 

Start the program with a controller connected, press a button with the window in focus, and notice that the "Controller is not connected" is always printed out into the debug output.

4
DotNet / Re: Issue using Joystick static methods
« on: November 09, 2014, 09:10:43 pm »
Here's my main game loop:

private void GameLoop()
{
    // Grab input
    _window.DispatchEvents();
    _inputProcessor.Update();

    // Update
    _world.Step(Constants.FPS);
    UpdateEntities();

    // Draw
    _window.Clear(Color.Black);
    DrawEntities();
    _window.Display();
}
 

_inputProcessor.Update() ends up calling CheckButtonState() shown in the post above.

5
DotNet / Re: Issue using Joystick static methods
« on: November 07, 2014, 08:14:24 am »
Yeah, I'm calling window.DispatchEvents() in my main game loop. But, calling Joystick.Update() at the beginning of each check fixed it.

Thanks for the quick help. You can close this now.

6
DotNet / Issue using Joystick static methods
« on: November 07, 2014, 07:59:11 am »
Whenever I press a button with my controller, the e.JoystickId that gets passed in when subscribing to JoystickButtonPressed is always 0. That is fine, however, if I call Joystick.IsConnected(0) it will always return false, as if the Joystick isn't plugged in. I noticed this because Joystick.IsButtonPressed() was always returning false for me whenever I would pass in the JoystickId along with the button that was just pressed. Am I doing something wrong or is this a known issue?

Example:
// My event handler
private void OnJoystickButtonPressed(object sender, JoystickButtonEventArgs e)
{
       _joystickId = e.JoystickId; // This always ends up being 0 for me. But the event does fire whenever I press a button, so it's not like my joystick isn't detected
       _joystickButtonEvents = true;
       _pushedButtons.Add(e.Button);
}

// This gets called every frame update until all button events are dequeued
private void CheckButtonState()
{
     foreach (uint button in _pushedButtons)
     {
         if (Joystick.IsConnected(_joystickId)) // This always returns false. I even tried all combinations (0-7) and it always returned false
         {
             if (Joystick.IsButtonPressed(_joystickId, button)) // This also always returns false but will never make it here since it doesn't get past the first check to see if the joystick is connected.
             {
                 PerformButtonAction(button);
             }
         }
     }
}

 

Pages: [1]