本文整理汇总了Java中com.almasb.fxgl.input.Input类的典型用法代码示例。如果您正苦于以下问题:Java Input类的具体用法?Java Input怎么用?Java Input使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Input类属于com.almasb.fxgl.input包,在下文中一共展示了Input类的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: setupMenuData
import com.almasb.fxgl.input.Input; //导入依赖的package包/类
public void setupMenuData() {
menuData = Arrays.asList(
new Pair<String, Runnable>("New Sim", () -> mainMenu.runNew(isFXGL)),
new Pair<String, Runnable>("Load Sim", () -> mainMenu.runLoad(isFXGL)),
//new Pair<String, Runnable>("Multiplayer", () -> {}),
new Pair<String, Runnable>("Tutorial", () -> {}),
new Pair<String, Runnable>("Benchmark", () -> {}),
new Pair<String, Runnable>("Settings", () -> mainMenu.runSettings()),
new Pair<String, Runnable>("Credits", () -> {}),
new Pair<String, Runnable>("Exit", () -> {
//Platform::exit
if (isFXGL) {
Input input = FXGL.getInput();
input.mockKeyPress(KeyCode.ESCAPE);
input.mockKeyRelease(KeyCode.ESCAPE);
}
else {
mainMenu.dialogOnExit(mainMenu.getPane());
}
})
);
}
示例5: openInitialWindows
import com.almasb.fxgl.input.Input; //导入依赖的package包/类
public void openInitialWindows() {
if (OS.contains("mac")) {
// SwingUtilities needed below for MacOSX
SwingUtilities.invokeLater(() -> {
desktop.openInitialWindows();
});
} else {
desktop.openInitialWindows();
}
quote = new QuotationPopup(this);
// popAQuote();
isMainSceneDoneLoading = true;
if (isFXGL) {
Input input = FXGL.getInput();
input.addInputMapping(new InputMapping("Open", KeyCode.O));
}
}
示例6: 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);
}
示例7: 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);
}
示例8: 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);
}
示例9: initInput
import com.almasb.fxgl.input.Input; //导入依赖的package包/类
@Override
protected void initInput() {
Input input = getInput();
input.addInputMapping(new InputMapping("Up", KeyCode.W));
input.addInputMapping(new InputMapping("Down", KeyCode.S));
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: initInput
import com.almasb.fxgl.input.Input; //导入依赖的package包/类
@Override
protected void initInput() {
// 1. get input service
Input input = getInput();
// 2. add input mappings (action name -> trigger name)
input.addInputMapping(new InputMapping("Print Line", KeyCode.F));
}