use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class RobotPlatformerSample method initInput.
@Override
protected void initInput() {
onKey(KeyCode.W, () -> getControl().jump());
onKey(KeyCode.F, () -> getControl().roll());
onKey(KeyCode.X, () -> getControl().die());
getInput().addAction(new UserAction("Left") {
@Override
protected void onAction() {
getControl().walkLeft();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onAction() {
getControl().walkRight();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.D);
getInput().addAction(new UserAction("Run Left") {
@Override
protected void onAction() {
getControl().runLeft();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.Q);
getInput().addAction(new UserAction("Run Right") {
@Override
protected void onAction() {
getControl().runRight();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.E);
getInput().addAction(new UserAction("Crouch Left") {
@Override
protected void onAction() {
getControl().crouchLeft();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.Z);
getInput().addAction(new UserAction("Crouch Right") {
@Override
protected void onAction() {
getControl().crouchRight();
}
@Override
protected void onActionEnd() {
getControl().stop();
}
}, KeyCode.C);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class InputSequenceSample method initInput.
@Override
protected void initInput() {
Input input = FXGL.getInput();
var sequence = new InputSequence(KeyCode.Q, KeyCode.W, KeyCode.E, KeyCode.R);
// the action fires only when the sequence above (Q, W, E, R) is complete
// useful for input combos
input.addAction(new UserAction("Print Line") {
@Override
protected void onActionBegin() {
System.out.println("Action Begin");
}
@Override
protected void onAction() {
System.out.println("On Action");
}
@Override
protected void onActionEnd() {
System.out.println("Action End");
}
}, sequence);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class VirtualControllerSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("test") {
@Override
protected void onActionBegin() {
System.out.println("start f");
}
@Override
protected void onAction() {
System.out.println("f");
}
@Override
protected void onActionEnd() {
System.out.println("end f");
}
}, KeyCode.F, VirtualButton.X);
getInput().addAction(new UserAction("test2") {
@Override
protected void onActionBegin() {
System.out.println("start g");
}
@Override
protected void onAction() {
System.out.println("g");
}
@Override
protected void onActionEnd() {
System.out.println("end g");
}
}, KeyCode.G, VirtualButton.Y);
getInput().addAction(new UserAction("test3") {
@Override
protected void onActionBegin() {
System.out.println("start h");
}
@Override
protected void onAction() {
System.out.println("h");
}
@Override
protected void onActionEnd() {
System.out.println("end h");
}
}, KeyCode.H, VirtualButton.A);
getInput().addAction(new UserAction("test4") {
@Override
protected void onActionBegin() {
System.out.println("start j");
}
@Override
protected void onAction() {
System.out.println("j");
}
@Override
protected void onActionEnd() {
System.out.println("end j");
}
}, KeyCode.J, VirtualButton.B);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class SaveSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
playerControl.left();
}
}, KeyCode.A);
input.addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
playerControl.right();
}
}, KeyCode.D);
input.addAction(new UserAction("Move Up") {
@Override
protected void onAction() {
playerControl.up();
}
}, KeyCode.W);
input.addAction(new UserAction("Move Down") {
@Override
protected void onAction() {
playerControl.down();
}
}, KeyCode.S);
input.addAction(new UserAction("Rotate") {
@Override
protected void onAction() {
player.rotateBy(1);
}
}, KeyCode.F);
input.addAction(new UserAction("Switch Types") {
@Override
protected void onAction() {
if (player.getTypeComponent().isType(Type.PLAYER)) {
player.getTypeComponent().setValue(Type.ENEMY);
enemy.getTypeComponent().setValue(Type.PLAYER);
} else {
player.getTypeComponent().setValue(Type.PLAYER);
enemy.getTypeComponent().setValue(Type.ENEMY);
}
}
}, KeyCode.G);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class InventorySample method initInput.
@Override
protected void initInput() {
inventorySubScene = new InventorySubScene();
inventorySubScene.getInput().addAction(new UserAction("Close Inventory") {
@Override
protected void onActionBegin() {
getSceneService().popSubScene();
}
}, KeyCode.F);
onKeyDown(KeyCode.F, "Open Inventory", () -> getSceneService().pushSubScene(inventorySubScene));
}
Aggregations