use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class InGamePanelSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Open/Close Panel") {
@Override
protected void onActionBegin() {
if (panel.isOpen())
panel.close();
else
panel.open();
}
}, KeyCode.TAB);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class InputSample method initInput.
@Override
protected void initInput() {
// 1. get input service
Input input = getInput();
// 2. add key/mouse bound actions
// when app is running press F to see output to console
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");
}
}, KeyCode.F);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class AudioSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Left") {
@Override
protected void onActionBegin() {
FXGLAssets.SOUND_NOTIFICATION.setBalance(-1.0);
getAudioPlayer().playSound(FXGLAssets.SOUND_NOTIFICATION);
}
}, KeyCode.A);
getInput().addAction(new UserAction("Right") {
@Override
protected void onActionBegin() {
FXGLAssets.SOUND_NOTIFICATION.setBalance(1.0);
getAudioPlayer().playSound(FXGLAssets.SOUND_NOTIFICATION);
}
}, KeyCode.D);
getInput().addAction(new UserAction("Mid") {
@Override
protected void onActionBegin() {
FXGLAssets.SOUND_NOTIFICATION.setBalance(0.0);
getAudioPlayer().playSound(FXGLAssets.SOUND_NOTIFICATION);
}
}, KeyCode.S);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class FlyingKeysSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Spawn Box") {
@Override
protected void onActionBegin() {
Entity box = createPhysicsEntity();
// 3. set hit box (-es) to specify bounding shape
box.getBoundingBoxComponent().addHitBox(new HitBox("Left", BoundingShape.box(20, 30)));
Button button = new Button(ALPHABET.charAt(FXGLMath.random(ALPHABET.length() - 1)) + "");
button.setPrefWidth(20);
button.setPrefHeight(30);
button.setOnAction(e -> System.out.println(button.getText()));
box.getViewComponent().setView(button);
getGameWorld().addEntity(box);
}
}, MouseButton.SECONDARY);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class EventsSample 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);
// 3. fire events manually if required
input.addAction(new UserAction("Fire My Event") {
@Override
protected void onActionBegin() {
getEventBus().fireEvent(new MyGameEvent(MyGameEvent.ANY));
}
}, KeyCode.F);
}
Aggregations