use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class RevoluteJointSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("LMB") {
private double x;
private double y;
@Override
protected void onActionBegin() {
x = getInput().getMouseXWorld();
y = getInput().getMouseYWorld();
}
@Override
protected void onActionEnd() {
var endx = getInput().getMouseXWorld();
var endy = getInput().getMouseYWorld();
spawnBullet(x, y, endx - x, endy - y);
}
}, MouseButton.PRIMARY);
onKeyDown(KeyCode.F, () -> {
Entity box = createPhysicsEntity();
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().addChild(texture("brick.png", 40, 40).superTexture(texture("brick.png", 40, 40), HorizontalDirection.RIGHT));
box.setRotationOrigin(new Point2D(40, 20));
getGameWorld().addEntity(box);
});
onBtnDown(MouseButton.SECONDARY, () -> {
Entity ball = createPhysicsEntity();
ball.getBoundingBoxComponent().addHitBox(new HitBox("Test", BoundingShape.circle(20)));
ball.getViewComponent().addChild(texture("ball.png", 40, 40));
ball.setRotationOrigin(new Point2D(20, 20));
getGameWorld().addEntity(ball);
});
}
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() {
player.translateX(-10);
}
}, KeyCode.A);
onKeyDown(KeyCode.F, "shake", () -> {
// getGameScene().getViewport().focusOn(new Point2D(2000, getAppHeight() / 2));
getGameScene().getViewport().shakeTranslational(5);
});
}
use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.
the class EntityActionSample method initInput.
@Override
protected void initInput() {
getInput().addAction(new UserAction("Move Now") {
@Override
protected void onActionBegin() {
entity.getComponent(ActionComponent.class).cancelActions();
entity.getComponent(ActionComponent.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
}
}, MouseButton.SECONDARY);
getInput().addAction(new UserAction("Queue Move Action") {
@Override
protected void onActionBegin() {
entity.getComponent(ActionComponent.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
}
}, MouseButton.PRIMARY);
getInput().addAction(new UserAction("Remove Current Action") {
@Override
protected void onActionBegin() {
Action a = actionsView.getSelectionModel().getSelectedItem();
if (a != null) {
entity.getComponent(ActionComponent.class).removeAction(a);
}
}
}, KeyCode.F);
}
Aggregations