diff --git a/flixel/input/actions/FlxAction.hx b/flixel/input/actions/FlxAction.hx index 48237e9046..27e37d06a0 100644 --- a/flixel/input/actions/FlxAction.hx +++ b/flixel/input/actions/FlxAction.hx @@ -342,6 +342,7 @@ class FlxAction implements IFlxDestroyable var _y:Null = null; var _timestamp:Int = 0; + @:deprecated("_checked is deprecated, use triggered, instead") var _checked:Bool = false; /** @@ -435,40 +436,33 @@ class FlxAction implements IFlxDestroyable */ public function check():Bool { + if (_timestamp == FlxG.game.ticks) + return triggered; // run no more than once per frame + _x = null; _y = null; - - if (_timestamp == FlxG.game.ticks) - { - triggered = _checked; - return _checked; // run no more than once per frame - } - + _timestamp = FlxG.game.ticks; - _checked = false; - - var len = inputs != null ? inputs.length : 0; - for (i in 0...len) + triggered = false; + + var i = inputs != null ? inputs.length : 0; + while (i-- > 0) // Iterate backwards, since we may remove items { - var j = len - i - 1; - var input = inputs[j]; - + final input = inputs[i]; + if (input.destroyed) { - inputs.splice(j, 1); + inputs.remove(input); continue; } - + input.update(); - + if (input.check(this)) - { - _checked = true; - } + triggered = true; } - - triggered = _checked; - return _checked; + + return triggered; } /** diff --git a/flixel/input/actions/FlxActionInput.hx b/flixel/input/actions/FlxActionInput.hx index 0d8f6cffb8..c74f52792d 100644 --- a/flixel/input/actions/FlxActionInput.hx +++ b/flixel/input/actions/FlxActionInput.hx @@ -110,22 +110,22 @@ enum FlxInputDevice * Just a bucket for some handy sentinel values. * @since 4.6.0 */ -class FlxInputDeviceID +enum abstract FlxInputDeviceID(Int) from Int to Int { /** * Means "every connected device of the given type" (ie all gamepads, all steam controllers, etc) */ - public static inline var ALL:Int = -1; + var ALL = -1; /** * Means "the first connected device that has an active input" (ie a pressed button or moved analog stick/trigger/etc) */ - public static inline var FIRST_ACTIVE:Int = -2; + var FIRST_ACTIVE = -2; /** * Means "no device" */ - public static inline var NONE:Int = -3; + var NONE = -3; } /** diff --git a/flixel/input/actions/FlxActionInputAnalog.hx b/flixel/input/actions/FlxActionInputAnalog.hx index 58264d1bfb..1dff292005 100644 --- a/flixel/input/actions/FlxActionInputAnalog.hx +++ b/flixel/input/actions/FlxActionInputAnalog.hx @@ -97,7 +97,7 @@ class FlxActionInputAnalogMouseMotion extends FlxActionInputAnalog deadZone = DeadZone; invertX = InvertX; invertY = InvertY; - super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis); + super(FlxInputDevice.MOUSE, -1, Trigger, Axis); } override public function update():Void @@ -144,7 +144,7 @@ class FlxActionInputAnalogMousePosition extends FlxActionInputAnalog */ public function new(Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER) { - super(FlxInputDevice.MOUSE, -1, cast Trigger, Axis); + super(FlxInputDevice.MOUSE, -1, Trigger, Axis); } override public function update():Void @@ -193,7 +193,7 @@ class FlxActionInputAnalogGamepad extends FlxActionInputAnalog */ public function new(InputID:FlxGamepadInputID, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, GamepadID:Int = FlxInputDeviceID.FIRST_ACTIVE) { - super(FlxInputDevice.GAMEPAD, InputID, cast Trigger, Axis, GamepadID); + super(FlxInputDevice.GAMEPAD, InputID, Trigger, Axis, GamepadID); } override public function update():Void @@ -265,7 +265,7 @@ class FlxActionInputAnalogSteam extends FlxActionInputAnalog @:allow(flixel.input.actions.FlxActionSet) function new(ActionHandle:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.ALL) { - super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, cast Trigger, Axis, DeviceID); + super(FlxInputDevice.STEAM_CONTROLLER, ActionHandle, Trigger, Axis, DeviceID); #if FLX_NO_STEAM FlxG.log.warn("steamwrap library not installed; steam inputs will be ignored."); #end @@ -310,9 +310,9 @@ class FlxActionInputAnalog extends FlxActionInput static inline var A_X = true; static inline var A_Y = false; - function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxInputState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE) + function new(Device:FlxInputDevice, InputID:Int, Trigger:FlxAnalogState, Axis:FlxAnalogAxis = EITHER, DeviceID:Int = FlxInputDeviceID.FIRST_ACTIVE) { - super(FlxInputType.ANALOG, Device, InputID, Trigger, DeviceID); + super(FlxInputType.ANALOG, Device, InputID, cast Trigger, DeviceID); axis = Axis; xMoved = new FlxInput(0); yMoved = new FlxInput(1);