standardize keyboard-based FlxCamera movement
This commit is contained in:
@@ -40,6 +40,8 @@
|
||||
<haxelib name="kiss" />
|
||||
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
||||
|
||||
<haxelib name="kiss-flixel" />
|
||||
|
||||
<haxelib name="nat-archive-tool" />
|
||||
|
||||
<!--In case you want to use the addons package-->
|
||||
|
||||
@@ -14,11 +14,11 @@ import flixel.text.FlxText;
|
||||
import flixel.util.FlxColor;
|
||||
using flixel.util.FlxSpriteUtil;
|
||||
import flixel.FlxCamera;
|
||||
import flixel.math.FlxVector;
|
||||
import flixel.math.FlxRect;
|
||||
import flixel.addons.plugin.FlxMouseControl;
|
||||
import flixel.input.mouse.FlxMouseEventManager;
|
||||
using StringTools;
|
||||
using kiss_flixel.CameraTools;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class PlayState extends FlxState implements ArchiveUI {}
|
||||
|
||||
@@ -117,36 +117,28 @@
|
||||
(+= uiCamera.y (* FlxG.mouse.wheel UI_SCROLL_FACTOR))
|
||||
// TODO allow changing the a scroll factor
|
||||
|
||||
// Control the UI camera with the arrow keys, and the playground camera with wasd:
|
||||
// Control the UI camera with WASD, and the playground camera with arrow keys:
|
||||
(var KEYBOARD_SCROLL_SPEED 200)
|
||||
(method cameraKeyControl [:FlxCamera camera :Void->Bool leftKey :Void->Bool rightKey :Void->Bool upKey :Void->Bool downKey]
|
||||
// but not when textInput is focused
|
||||
(unless (and textInput textInput.hasFocus)
|
||||
(let [scrollPerSec (/ KEYBOARD_SCROLL_SPEED 60)
|
||||
&mut :FlxVector movement (new FlxPoint)]
|
||||
(when (leftKey) (-= movement.x 1))
|
||||
(when (rightKey) (+= movement.x 1))
|
||||
(when (upKey) (-= movement.y 1))
|
||||
(when (downKey) (+= movement.y 1))
|
||||
(when (< 0 movement.length)
|
||||
(set movement (movement.normalize)))
|
||||
(movement.scale scrollPerSec)
|
||||
(+= camera.scroll.x movement.x)
|
||||
(+= camera.scroll.y movement.y))))
|
||||
|
||||
(FlxG.camera.updateKeyControl
|
||||
elapsed
|
||||
KEYBOARD_SCROLL_SPEED
|
||||
->{FlxG.keys.pressed.LEFT}
|
||||
->{FlxG.keys.pressed.RIGHT}
|
||||
->{FlxG.keys.pressed.UP}
|
||||
->{FlxG.keys.pressed.DOWN})
|
||||
|
||||
// don't move the ui camera before ui has been placed -- new UI elements could appear offscreen
|
||||
(when (> uiGroup.length 0)
|
||||
(cameraKeyControl uiCamera
|
||||
->{FlxG.keys.pressed.LEFT}
|
||||
->{FlxG.keys.pressed.RIGHT}
|
||||
->{FlxG.keys.pressed.UP}
|
||||
->{FlxG.keys.pressed.DOWN}))
|
||||
|
||||
(cameraKeyControl FlxG.camera
|
||||
->{FlxG.keys.pressed.A}
|
||||
->{FlxG.keys.pressed.D}
|
||||
->{FlxG.keys.pressed.W}
|
||||
->{FlxG.keys.pressed.S}))
|
||||
(unless (and textInput textInput.hasFocus)
|
||||
(uiCamera.updateKeyControl
|
||||
elapsed
|
||||
KEYBOARD_SCROLL_SPEED
|
||||
// TODO support dvorak
|
||||
->{FlxG.keys.pressed.A}
|
||||
->{FlxG.keys.pressed.D}
|
||||
->{FlxG.keys.pressed.W}
|
||||
->{FlxG.keys.pressed.S}))))
|
||||
|
||||
(method :Void typeCommand []
|
||||
(enterText
|
||||
|
||||
Reference in New Issue
Block a user