本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}