/** * set up some key actions. - SPACE to release a new object, - ESC to quit the game - TAB to * enable / disable the GUI GameState */ private void setupInput() { input.addAction( new InputAction() { public void performAction(InputActionEvent evt) { if (evt.getTriggerPressed()) { PhysicsGame.get().getGame().finish(); } } }, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_ESCAPE, InputHandler.AXIS_NONE, false); input.addAction( new InputAction() { public void performAction(InputActionEvent evt) { if (evt.getTriggerPressed()) { spawnObject(); } } }, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_SPACE, InputHandler.AXIS_NONE, false); input.addAction( new InputAction() { public void performAction(InputActionEvent evt) { if (evt.getTriggerPressed()) { if (GameStateManager.getInstance().getChild("gui").isActive()) { movementInput.setEnabled(true); GameStateManager.getInstance().getChild("gui").setActive(false); } else { movementInput.setEnabled(false); GameStateManager.getInstance().getChild("gui").setActive(true); } } } }, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_TAB, InputHandler.AXIS_NONE, false); }
/** * we update the input controllers and some physic object if needed, then we update the physics * world and call updateGeometricstate() which happens in super.update(). */ @Override public void update(float tpf) { input.update(tpf); // swing.update(); if (movementInput.isEnabled()) { movementInput.update(tpf); } super.update(tpf); }
public JMEAction(String name, InputHandler inputHandler) { button = new SyntheticButton(name); inputHandler.addAction( this, button.getDeviceName(), button.getIndex(), InputHandler.AXIS_NONE, false); delegate = new AbstractAction(name) { private static final long serialVersionUID = 1L; public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { if (changeSupport == null) { changeSupport = new SwingPropertyChangeSupport(JMEAction.this); } super.addPropertyChangeListener(listener); } public void actionPerformed(ActionEvent e) {} }; }