use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class JointSample 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(40, 40)));
box.getBoundingBoxComponent().addHitBox(new HitBox("Right", new Point2D(40, 0), BoundingShape.box(40, 40)));
box.getViewComponent().setView(new Rectangle(80, 40, Color.BLUE));
getGameWorld().addEntity(box);
}
}, MouseButton.PRIMARY);
input.addAction(new UserAction("Spawn Ball") {
@Override
protected void onActionBegin() {
Entity ball = createPhysicsEntity();
// 3. set hit box to specify bounding shape
ball.getBoundingBoxComponent().addHitBox(new HitBox("Test", BoundingShape.circle(20)));
ball.getViewComponent().setView(new Circle(20, Color.RED));
getGameWorld().addEntity(ball);
}
}, MouseButton.SECONDARY);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class ScrollingBackgroundSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
player.translateX(10);
}
}, KeyCode.D);
getInput().addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
if (player.getX() >= 10)
player.translateX(-10);
}
}, KeyCode.A);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class ViewportSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Move Viewport Up") {
@Override
protected void onAction() {
getGameScene().getViewport().setY(getGameScene().getViewport().getY() - 5);
}
}, KeyCode.W);
getInput().addAction(new UserAction("Move Viewport Down") {
@Override
protected void onAction() {
getGameScene().getViewport().setY(getGameScene().getViewport().getY() + 5);
}
}, KeyCode.S);
getInput().addAction(new UserAction("Print Coords") {
@Override
protected void onActionBegin() {
// System.out.println(getInput().getMousePositionWorld());
// cinematicViewport();
cinematicViewportBezier();
}
}, MouseButton.PRIMARY);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class ViewportZoomSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
e1.translateX(-5);
}
}, KeyCode.A);
input.addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
e1.translateX(5);
}
}, KeyCode.D);
input.addAction(new UserAction("Move Up") {
@Override
protected void onAction() {
e1.translateY(-5);
}
}, KeyCode.W);
input.addAction(new UserAction("Move Down") {
@Override
protected void onAction() {
e1.translateY(5);
}
}, KeyCode.S);
input.addAction(new UserAction("Move Left2") {
@Override
protected void onAction() {
e2.translateX(-5);
}
}, KeyCode.LEFT);
input.addAction(new UserAction("Move Right2") {
@Override
protected void onAction() {
e2.translateX(5);
}
}, KeyCode.RIGHT);
input.addAction(new UserAction("Move Up2") {
@Override
protected void onAction() {
e2.translateY(-5);
}
}, KeyCode.UP);
input.addAction(new UserAction("Move Down2") {
@Override
protected void onAction() {
e2.translateY(5);
}
}, KeyCode.DOWN);
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class AchievementsSample method initInput.
@Override
protected void initInput() {
Input input = getInput();
input.addAction(new UserAction("Move Left") {
@Override
protected void onAction() {
playerControl.left();
getGameState().increment("moved", (int) (300 * tpf()));
}
}, KeyCode.A);
input.addAction(new UserAction("Move Right") {
@Override
protected void onAction() {
playerControl.right();
getGameState().increment("moved", (int) (300 * tpf()));
}
}, KeyCode.D);
input.addAction(new UserAction("Move Up") {
@Override
protected void onAction() {
playerControl.up();
getGameState().increment("moved", (int) (300 * tpf()));
}
}, KeyCode.W);
input.addAction(new UserAction("Move Down") {
@Override
protected void onAction() {
playerControl.down();
getGameState().increment("moved", (int) (300 * tpf()));
}
}, KeyCode.S);
}
Aggregations