当前位置: 首页>>代码示例>>Java>>正文


Java Input.addAction方法代码示例

本文整理汇总了Java中com.almasb.fxgl.input.Input.addAction方法的典型用法代码示例。如果您正苦于以下问题:Java Input.addAction方法的具体用法?Java Input.addAction怎么用?Java Input.addAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.almasb.fxgl.input.Input的用法示例。


在下文中一共展示了Input.addAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput();

    input.addAction(new UserAction("Spawn Explosion") {
        @Override
        protected void onActionBegin() {
            // 1. create entity
            Entity explosion = new Entity();
            explosion.setPosition(input.getMousePositionWorld());

            // 2. create and configure emitter + control
            ParticleEmitter emitter = ParticleEmitters.newExplosionEmitter(400);
            ParticleControl control = new ParticleControl(emitter);

            // we also want the entity to destroy itself when particle control is done
            control.setOnFinished(explosion::removeFromWorld);

            // 3. add control to entity
            explosion.addControl(control);

            // 4. add entity to game world
            getGameWorld().addEntity(explosion);
        }
    }, MouseButton.PRIMARY);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:27,代码来源:ParticlesSample.java

示例2: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:25,代码来源:InputSample.java

示例3: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:25,代码来源:FlyingKeysSample.java

示例4: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput();

    input.addAction(new UserAction("Place Tower") {
        private Rectangle2D worldBounds = new Rectangle2D(0, 0, getWidth(), getHeight() - 100 - 40);

        @Override
        protected void onActionBegin() {
            if (worldBounds.contains(input.getMousePositionWorld())) {
                placeTower();
            }
        }
    }, MouseButton.PRIMARY);
}
 
开发者ID:AlmasB,项目名称:FXGLGames,代码行数:16,代码来源:TowerDefenseApp.java

示例5: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);

    input.addAction(new UserAction("Shoot") {
        @Override
        protected void onActionBegin() {
            playerControl.shoot();
        }
    }, KeyCode.F);
}
 
开发者ID:AlmasB,项目名称:FXGLGames,代码行数:40,代码来源:BattleTanksApp.java

示例6: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput();

    input.addAction(new UserAction("Shoot") {
        @Override
        protected void onActionBegin() {
            shoot();
        }
    }, MouseButton.PRIMARY);
}
 
开发者ID:AlmasB,项目名称:FXGLGames,代码行数:12,代码来源:CannonApp.java

示例7: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput();

    input.addAction(new UserAction("Shoot") {
        @Override
        protected void onActionBegin() {
            getGameWorld().spawn("Bullet", input.getMouseXWorld(), getHeight() - 10);
        }
    }, MouseButton.PRIMARY);
}
 
开发者ID:AlmasB,项目名称:FXGLGames,代码行数:12,代码来源:ShooterApp.java

示例8: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:33,代码来源:PhysicsSample.java

示例9: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput(); // get input service

    input.addAction(new UserAction("Move Right") {
        @Override
        protected void onAction() {
            player.translateX(5); // move right 5 pixels
            getGameState().increment("pixelsMoved", +5);
        }
    }, KeyCode.D);

    input.addAction(new UserAction("Move Left") {
        @Override
        protected void onAction() {
            player.translateX(-5); // move left 5 pixels
            getGameState().increment("pixelsMoved", +5);
        }
    }, KeyCode.A);

    input.addAction(new UserAction("Move Up") {
        @Override
        protected void onAction() {
            player.translateY(-5); // move up 5 pixels
            getGameState().increment("pixelsMoved", +5);
        }
    }, KeyCode.W);

    input.addAction(new UserAction("Move Down") {
        @Override
        protected void onAction() {
            player.translateY(5); // move down 5 pixels
            getGameState().increment("pixelsMoved", +5);
        }
    }, KeyCode.S);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:37,代码来源:BasicGameApp.java

示例10: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:41,代码来源:EventsSample.java

示例11: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:36,代码来源:JointSample.java

示例12: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);

    input.addAction(new UserAction("Shockwave") {
        @Override
        protected void onActionBegin() {
            playerControl.releaseShockwave();
        }
    }, KeyCode.E);

    input.addAction(new UserAction("Shoot") {
        @Override
        protected void onAction() {
            playerControl.shoot(input.getMousePositionWorld());
        }
    }, MouseButton.PRIMARY);
}
 
开发者ID:AlmasB,项目名称:FXGLGames,代码行数:47,代码来源:GeoWarsApp.java

示例13: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);

    input.addAction(new UserAction("Rotate") {
        @Override
        protected void onAction() {
            player.getRotationComponent().rotateBy(1);
        }
    }, KeyCode.F);

    input.addAction(new UserAction("Switch Types") {
        @Override
        protected void onAction() {
            if (player.getTypeComponent().isType(Type.PLAYER)) {
                player.getTypeComponent().setValue(Type.ENEMY);
                enemy.getTypeComponent().setValue(Type.PLAYER);
            } else {
                player.getTypeComponent().setValue(Type.PLAYER);
                enemy.getTypeComponent().setValue(Type.ENEMY);
            }
        }
    }, KeyCode.G);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:53,代码来源:SaveSample.java

示例14: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@Override
protected void initInput() {
    Input input = getInput();

    input.addAction(new UserAction("Left") {
        @Override
        protected void onActionBegin() {
            player.getComponent(PhysicsComponent.class).setLinearVelocity(new Point2D(-200, 0));
        }
    }, KeyCode.A);

    input.addAction(new UserAction("Right") {
        @Override
        protected void onActionBegin() {
            player.getComponent(PhysicsComponent.class).setLinearVelocity(new Point2D(200, 0));
        }
    }, KeyCode.D);

    input.addAction(new UserAction("Jump") {
        @Override
        protected void onActionBegin() {
            PhysicsComponent physics = player.getComponent(PhysicsComponent.class);

            if (physics.isOnGround()) {
                double dx = physics.getLinearVelocity().getX();

                physics.setLinearVelocity(new Point2D(dx, -100));
            }
        }
    }, KeyCode.W);

    input.addAction(new UserAction("Grow") {
        @Override
        protected void onActionBegin() {
            double x = player.getX();
            double y = player.getY();

            player.removeFromWorld();

            player = createPlayer(x, y, 60, 80);
        }
    }, KeyCode.SPACE);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:44,代码来源:PlatformerSample.java

示例15: initInput

import com.almasb.fxgl.input.Input; //导入方法依赖的package包/类
@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);

    input.addAction(new UserAction("Rotate CCW") {
        @Override
        protected void onAction() {
            player.rotateBy(-5);
        }
    }, KeyCode.Q);

    input.addAction(new UserAction("Rotate CW") {
        @Override
        protected void onAction() {
            player.rotateBy(5);
        }
    }, KeyCode.E);
}
 
开发者ID:AlmasB,项目名称:FXGL,代码行数:47,代码来源:PhysicsSample2.java


注:本文中的com.almasb.fxgl.input.Input.addAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。