update
This commit is contained in:
3
input_mouselock/README.md
Normal file
3
input_mouselock/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
Keyboard `Escape` to toggle mouse lock.
|
||||
|
||||
https://api.leenkx3d.org/iron/system/Mouse.html
|
||||
28
input_mouselock/Sources/lnx/LockTrait.hx
Normal file
28
input_mouselock/Sources/lnx/LockTrait.hx
Normal file
@ -0,0 +1,28 @@
|
||||
package lnx;
|
||||
|
||||
import iron.math.Vec4;
|
||||
import iron.system.Input;
|
||||
|
||||
class LockTrait extends iron.Trait {
|
||||
|
||||
public function new() {
|
||||
|
||||
super();
|
||||
|
||||
var mouse = Input.getMouse();
|
||||
var kb = Input.getKeyboard();
|
||||
|
||||
notifyOnUpdate(() -> {
|
||||
if (mouse.started("left")) {
|
||||
mouse.lock();
|
||||
} else if (kb.started("escape")) {
|
||||
mouse.unlock();
|
||||
}
|
||||
var cube = iron.Scene.active.getChild("Cube");
|
||||
if (cube != null) {
|
||||
cube.transform.rotate(Vec4.zAxis(), mouse.movementX * 0.002);
|
||||
cube.transform.rotate(Vec4.xAxis(), mouse.movementY * 0.002);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
input_mouselock/input_mouselock.blend
Normal file
BIN
input_mouselock/input_mouselock.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user