Files
Leenkx_Examples/input_mouselock/Sources/lnx/LockTrait.hx
2026-05-06 17:52:45 -07:00

29 lines
564 B
Haxe

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);
}
});
}
}