Moving the Mouse Cursor via Gamepad Input

74 views
Skip to first unread message

Eric Bernier

unread,
Apr 26, 2015, 10:12:32 PM4/26/15
to haxef...@googlegroups.com
Hi all,

I set up a simple scene to tinker with Gamepad support. Right now my update method looks as follows:


override public function update():Void {
        curGamepad = FlxG.gamepads.lastActive;
if (curGamepad != null) {
    updateAxis(curGamepad);
}
super.update();
}

The gamepad object is an instance of FlxGamepad. The updateAxis method reads as follows:

public function updateAxis(gamepad:FlxGamepad):Void
{
var xAxisValue:Float = gamepad.getXAxis(XboxButtonID.LEFT_ANALOGUE_X);
var yAxisValue:Float = gamepad.getYAxis(XboxButtonID.LEFT_ANALOGUE_Y);
var angle:Float;

if ((xAxisValue != 0) || (yAxisValue != 0))
{
angle = Math.atan2(yAxisValue, xAxisValue);

trace(STICK_MOVEMENT_RANGE * Math.cos(angle));

FlxG.mouse.x += STICK_MOVEMENT_RANGE * Math.cos(angle);
FlxG.mouse.y += STICK_MOVEMENT_RANGE * Math.sin(angle);
}
}

The output from the trace statement looks good, however my mouse cursor doesn't update its position as expected. Is modifying the mouse x,y coordinates like this not allowed? If so, is there an easy way to move the mouse cursor via a Gamepad? Thanks in advance for any help, and/or hints.

-Eric

Gama11

unread,
Apr 28, 2015, 7:46:38 AM4/28/15
to haxef...@googlegroups.com
FlxG.mouse.x / y are indeed read-only (although this is not reflected properly in the code since FlxMouse extends FlxPoint - on the latest release anyway).

You could simply hide the mouse and use a FlxSprite as a cursor. You might also find flixel-ui's Cursor demo helpful.
Reply all
Reply to author
Forward
0 new messages