Search in sources :

Example 11 with UserAction

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

Example 12 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 = 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)

Example 13 with UserAction

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

Example 14 with UserAction

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);
}
Also used : UserAction(com.almasb.fxgl.input.UserAction) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) PhysicsComponent(com.almasb.fxgl.physics.PhysicsComponent) Input(com.almasb.fxgl.input.Input) FXGLMath(com.almasb.fxgl.core.math.FXGLMath) GameSettings(com.almasb.fxgl.settings.GameSettings) UserAction(com.almasb.fxgl.input.UserAction) BoundingShape(com.almasb.fxgl.physics.BoundingShape) Duration(javafx.util.Duration) BodyType(com.almasb.fxgl.physics.box2d.dynamics.BodyType) FixtureDef(com.almasb.fxgl.physics.box2d.dynamics.FixtureDef) Entities(com.almasb.fxgl.entity.Entities) HitBox(com.almasb.fxgl.physics.HitBox) GameApplication(com.almasb.fxgl.app.GameApplication) Entity(com.almasb.fxgl.entity.Entity) Entity(com.almasb.fxgl.entity.Entity) Input(com.almasb.fxgl.input.Input) HitBox(com.almasb.fxgl.physics.HitBox) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton)

Example 15 with UserAction

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);
}
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