drag to select fix deselection when clicking background

This commit is contained in:
2022-08-17 23:38:14 +00:00
parent 86e8d71661
commit 2955657cb4

View File

@@ -56,15 +56,18 @@ class DragToSelectPlugin extends FlxBasic {
dragStates[FlxG.state].selectedSprites = []; dragStates[FlxG.state].selectedSprites = [];
} }
var wasJustPressed = false;
public override function update(elapsed:Float) { public override function update(elapsed:Float) {
if (dragStates.exists(FlxG.state)) { if (dragStates.exists(FlxG.state)) {
var dragState = dragStates[FlxG.state]; var dragState = dragStates[FlxG.state];
dragState.debugLayer.clear(); dragState.debugLayer.clear();
// Might have to skip a frame after justPressed, so KissExtendedSprites // have to skip a frame after justPressed, so KissExtendedSprites
// can get first access to the mouse input // can get first access to the mouse input
if (FlxMouseControl.dragTarget == null) { if (FlxMouseControl.dragTarget == null) {
if (FlxG.mouse.justPressed) { if (wasJustPressed && FlxMouseControl.clickTarget == null) {
deselectSprites();
dragState.firstCorner = FlxG.mouse.getWorldPosition(dragState.camera); dragState.firstCorner = FlxG.mouse.getWorldPosition(dragState.camera);
} }
dragState.secondCorner = FlxG.mouse.getWorldPosition(dragState.camera); dragState.secondCorner = FlxG.mouse.getWorldPosition(dragState.camera);
@@ -111,6 +114,7 @@ class DragToSelectPlugin extends FlxBasic {
} }
} }
} }
wasJustPressed = FlxG.mouse.justPressed;
} }
} }
} }