forked from LeenkxTeam/Leenkx_Examples
update
This commit is contained in:
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user