Search in sources :

Example 16 with UserAction

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.getControl(ActionControl.class).clearActions();
            entity.getControl(ActionControl.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.PRIMARY);
    getInput().addAction(new UserAction("Queue Move Action") {

        @Override
        protected void onActionBegin() {
            entity.getControl(ActionControl.class).addAction(new MoveAction(getInput().getMouseXWorld(), getInput().getMouseYWorld()));
        }
    }, MouseButton.SECONDARY);
    getInput().addAction(new UserAction("Remove Current Action") {

        @Override
        protected void onActionBegin() {
            Action<?> a = actionsView.getSelectionModel().getSelectedItem();
            if (a != null) {
                entity.getControl(ActionControl.class).removeAction(a);
            }
        }
    }, KeyCode.F);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Action(com.almasb.fxgl.entity.action.Action) UserAction(com.almasb.fxgl.input.UserAction)

Example 17 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class RangeTest 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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input)

Example 18 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class EntityPerformanceTest method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Test Add") {

        @Override
        protected void onActionBegin() {
            testAdd();
        }
    }, KeyCode.F);
    getInput().addAction(new UserAction("Test Remove") {

        @Override
        protected void onActionBegin() {
            testRemove();
        }
    }, KeyCode.G);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 19 with UserAction

use of com.almasb.fxgl.input.UserAction in project FXGL by AlmasB.

the class BreakoutApp method initInput.

@Override
protected void initInput() {
    getInput().addAction(new UserAction("Up 1") {

        @Override
        protected void onAction() {
            paddle1.translateY(-PADDLE_SPEED);
        }
    }, KeyCode.W);
    getInput().addAction(new UserAction("Down 1") {

        @Override
        protected void onAction() {
            paddle1.translateY(PADDLE_SPEED);
        }
    }, KeyCode.S);
    getInput().addAction(new UserAction("Up 2") {

        @Override
        protected void onAction() {
            paddle2.translateY(-PADDLE_SPEED);
        }
    }, KeyCode.UP);
    getInput().addAction(new UserAction("Down 2") {

        @Override
        protected void onAction() {
            paddle2.translateY(PADDLE_SPEED);
        }
    }, KeyCode.DOWN);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction)

Example 20 with UserAction

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 = FXGL.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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Input(com.almasb.fxgl.input.Input)

Aggregations

UserAction (com.almasb.fxgl.input.UserAction)48 Input (com.almasb.fxgl.input.Input)23 Entity (com.almasb.fxgl.entity.Entity)6 Point2D (javafx.geometry.Point2D)6 HitBox (com.almasb.fxgl.physics.HitBox)5 PhysicsComponent (com.almasb.fxgl.physics.PhysicsComponent)3 Rectangle (javafx.scene.shape.Rectangle)3 GameApplication (com.almasb.fxgl.app.GameApplication)2 Action (com.almasb.fxgl.entity.action.Action)2 GameSettings (com.almasb.fxgl.settings.GameSettings)2 Circle (javafx.scene.shape.Circle)2 VoronoiSubdivision (com.almasb.fxgl.algorithm.VoronoiSubdivision)1 DSLKt (com.almasb.fxgl.app.DSLKt)1 FXGLMath (com.almasb.fxgl.core.math.FXGLMath)1 SlowTimeEffect (com.almasb.fxgl.dsl.effects.SlowTimeEffect)1 ParticleControl (com.almasb.fxgl.effect.ParticleControl)1 ParticleEmitter (com.almasb.fxgl.effect.ParticleEmitter)1 Entities (com.almasb.fxgl.entity.Entities)1 ContinuousAction (com.almasb.fxgl.entity.action.ContinuousAction)1 InstantAction (com.almasb.fxgl.entity.action.InstantAction)1