use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class BehaviorSample 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);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class VoronoiSample method initInput.
@Override
protected void initInput() {
onKey(KeyCode.Q, "dec", () -> inc("hp", -0.01));
onKey(KeyCode.E, "inc", () -> inc("hp", +0.01));
getInput().addAction(new UserAction("Voronoi") {
@Override
protected void onActionBegin() {
VoronoiSubdivision.divide(getAppBounds(), 100, 2).forEach(p -> {
p.setStrokeWidth(1.5);
p.strokeProperty().bind(getop("stroke"));
p.setFill(Color.RED);
p.opacityProperty().bind(new SimpleDoubleProperty(1).subtract(getdp("hp")).multiply(distance(p) / 500 * 3));
getGameScene().addUINode(p);
});
Text text = getUIFactory().newText("", Color.BLACK, 18.0);
text.setTranslateX(50);
text.setTranslateY(50);
text.textProperty().bind(getdp("hp").asString("%.2f"));
getGameScene().addUINode(text);
}
}, KeyCode.F);
}
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.getRotationComponent().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 WheelMenuSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Open/Close WheelMenu") {
@Override
protected void onActionBegin() {
if (menu.isOpen())
menu.close();
else
menu.open();
menu.setTranslateX(getInput().getMouseXWorld() - 25);
menu.setTranslateY(getInput().getMouseYWorld() - 75);
}
}, MouseButton.SECONDARY);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class SelectedEntitySample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Make unselectable") {
@Override
protected void onActionBegin() {
player.getComponent(SelectableComponent.class).setValue(false);
}
}, KeyCode.F);
getInput().addAction(new UserAction("Make selectable") {
@Override
protected void onActionBegin() {
player.getComponent(SelectableComponent.class).setValue(true);
}
}, KeyCode.G);
}
Aggregations