本文整理汇总了Java中net.java.games.input.Controller.Type方法的典型用法代码示例。如果您正苦于以下问题:Java Controller.Type方法的具体用法?Java Controller.Type怎么用?Java Controller.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.java.games.input.Controller
的用法示例。
在下文中一共展示了Controller.Type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getButtonController
import net.java.games.input.Controller; //导入方法依赖的package包/类
/**
* Description of the Method
*
* @param index Description of the Parameter
* @return Description of the Return Value
*/
public static int getButtonController(int index) {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
int controllerCount = 0;
for (int d = 0; d < cs.length; d++) {
Controller.Type type = cs[d].getType();
if ((type == Controller.Type.GAMEPAD) || (type == Controller.Type.STICK) || cs[d].getName().toLowerCase().contains("wiimote") || cs[d].getName().toLowerCase().contains("shuttle")) {
if (controllerCount == index) {
return d;
}
controllerCount++;
}
}
return -1;
}
示例2: pollAllButtons
import net.java.games.input.Controller; //导入方法依赖的package包/类
/**
* Description of the Method
*/
public void pollAllButtons() {
ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment();
Controller[] cs = ce.getControllers();
for (Controller cc : cs) {
Controller.Type type = cc.getType();
//if (type == Controller.Type.MOUSE || type == Controller.Type.KEYBOARD) {
// continue;
//} else
if (type == Controller.Type.GAMEPAD || type == Controller.Type.STICK) {
cc.poll();
} else if (type == Controller.Type.UNKNOWN) {
cc.poll();
} else if (cc.getName().toLowerCase().contains("wiimote")) {
cc.poll();
}
}
}
示例3: findGamePad
import net.java.games.input.Controller; //导入方法依赖的package包/类
/**
* Possibly useful for Auto-Find controller Search the array of controllers
* until a suitable game pad controller is found (either of type GAMEPAD or
* STICK).
*/
private Controller findGamePad(Controller[] cs) {
Controller.Type type;
int i = 0;
while (i < cs.length) {
type = cs[i].getType();
if ((type == Controller.Type.GAMEPAD) || (type == Controller.Type.STICK))
break;
i++;
}
if (i == cs.length) {
log.warn("No game pad found");
} else
log.info("Game pad index: " + i);
return cs[i];
}
示例4: initializeJoysticks
import net.java.games.input.Controller; //导入方法依赖的package包/类
private void initializeJoysticks() {
final Controller[] controllers = controllerEnvironment.getControllers();
for (int i = 0; i < controllers.length; i++) {
final Controller j = controllers[i];
final Controller.Type t = j.getType();
if (t == Controller.Type.GAMEPAD || t == Controller.Type.STICK) {
joystickIds.put(j, i);
joysticks.add(j);
}
}
getPreferencesManager().setJoystickPositions(joystickPositions);
joysticks.stream().forEach(this::fireJoystickAdded);
}
示例5: JoystickManager
import net.java.games.input.Controller; //导入方法依赖的package包/类
public JoystickManager() {
controllerEnvironment = ControllerEnvironment.getDefaultEnvironment();
initializeJoysticks();
controllerListener = new ControllerListener() {
@Override
public void controllerRemoved(final ControllerEvent ev) {
final Controller c = ev.getController();
final Controller.Type t = c.getType();
if (t.equals(Controller.Type.STICK) || t.equals(Controller.Type.GAMEPAD)) {
synchronized (joysticks) {
joysticks.remove(ev.getController());
joystickIds.remove(c);
}
SwingUtilities.invokeLater(() -> fireJoystickRemoved(c));
}
}
@Override
public void controllerAdded(final ControllerEvent ev) {
SwingUtilities.invokeLater(() -> {
final Controller c = ev.getController();
final Controller.Type t = c.getType();
if (t.equals(Controller.Type.STICK) || t.equals(Controller.Type.GAMEPAD)) {
synchronized (joysticks) {
joystickIds.put(c, joystickIds.size());
joysticks.add(ev.getController());
}
SwingUtilities.invokeLater(() -> fireJoystickAdded(c));
}
});
}
};
controllerEnvironment.addControllerListener(controllerListener);
getCommunicationManager().setJoystickUpdater(robotJoysticks -> {
synchronized (joysticks) {
for (int j = 0; j < Math.min(joysticks.size(), robotJoysticks.size()); j++) {
final Controller dsJoystick = joysticks.get(j);
final Joystick robotJoystick = robotJoysticks.get(j);
if (dsJoystick.poll()) {
final Component[] components = dsJoystick.getComponents();
int axisIndex = 1;
int buttonIndex = 1;
for (Component c : components) {
if (c.isAnalog() && axisIndex <= Joystick.NUM_AXES) {
robotJoystick.setAxis(axisIndex++, c.getPollData());
} else if (buttonIndex <= Joystick.NUM_BUTTONS) {
robotJoystick.setButton(buttonIndex++, c.getPollData() == 1.0f);
}
}
} else {
joysticks.remove(j);
SwingUtilities.invokeLater(() -> fireJoystickRemoved(dsJoystick));
}
}
}
});
}