HaxeFlixel / HaxeFlixel/flixel

FlxG.gamepads.getByID().pressed not working properly with multiple controllers

Open
#1,892 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haxe
Stars
2.2k
Forks
522
Avg merge
34m
Merged PRs (30d)
1

Description

  • Flixel version: git @ 5f76de6
  • OpenFL version: 3.6.1
  • Lime version: 2.9.1
  • Affected targets: Neko, Windows

Code snippet reproducing the issue:

package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.math.FlxMath;

class MenuState extends FlxState
{

    private var gamepadList:FlxText;
    private var state:FlxText;

    private var activeID:Int;

    override public function create():Void
    {
        gamepadList = new FlxText(10, 10, 0, "", 16);
        add(gamepadList);

        state = new FlxText(10, 100, 0, "", 16);
        add(state);

        super.create();
    }

    override public function update(elapsed:Float):Void
    {       
        activeID = FlxG.gamepads.getFirstActiveGamepadID();

        gamepadList.text = "";
        state.text = "";

        for (gamepad in FlxG.gamepads.getActiveGamepads()) {
            gamepadList.text += gamepad.detectedModel + ' at ID #' + gamepad.id + '\n';
        }

        state.text += "Active Gamepads: " + FlxG.gamepads.numActiveGamepads;
        state.text += "\nFirst Active Gamepad ID: " + activeID;

        if (activeID > -1)
            state.text += "\nFlxG.gamepads.getByID(" + activeID + ").pressed.ANY returned " + FlxG.gamepads.getByID(activeID).pressed.ANY;

        super.update(elapsed);
    }
}

Observed behavior:
Whenever you have more than one controller plugged in, at least two of them need to have a button pressed in order for the code above to return true. Pressing only one controller returns false, for that controller ID. Same goes for justPressed and justReleased. Note that FlxG.gamepads.anyInput() will behave as expected.

Expected behavior:
The controller that is active and pressed to return true.


Here's an example project exhibiting the issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the linked example project with multiple controllers and observe FlxG.gamepads.getByID(...).pressed, justPressed, and justReleased alongside anyInput(). Start from the gamepad manager entry points named in the report and trace how controller IDs are selected. Done means a button press on one controller makes that controller's per-ID state return true without requiring input from another controller.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.