本文整理汇总了Java中net.java.games.input.Component.getIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Java Component.getIdentifier方法的具体用法?Java Component.getIdentifier怎么用?Java Component.getIdentifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.java.games.input.Component
的用法示例。
在下文中一共展示了Component.getIdentifier方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadIdentifiers
import net.java.games.input.Component; //导入方法依赖的package包/类
private void loadIdentifiers(int controllerIdx, Controller c){
Component[] ces = c.getComponents();
int numButtons = 0;
int numAxes = 0;
xAxis = -1;
yAxis = -1;
for (Component comp : ces){
Identifier id = comp.getIdentifier();
if (id instanceof Button){
buttonIdsToIndices[controllerIdx].put((Button)id, numButtons);
numButtons ++;
}else if (id instanceof Axis){
Axis axis = (Axis) id;
if (axis == Axis.X){
xAxis = numAxes;
}else if (axis == Axis.Y){
yAxis = numAxes;
}
axisIdsToIndices[controllerIdx].put((Axis)id, numAxes);
numAxes ++;
}
}
}
示例2: findCompIndex
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* TODO - remove this - not needed Search through comps[] for id, returning
* the corresponding array index, or -1
*/
private int findCompIndex(Component[] comps, Component.Identifier id, String nm) {
Component c;
for (int i = 0; i < comps.length; i++) {
c = comps[i];
if ((c.getIdentifier() == id) && !c.isRelative()) {
log.info("Found " + c.getName() + "; index: " + i);
return i;
}
}
log.info("No " + nm + " component found");
return -1;
}
示例3: getAvailablePadControllers
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* This method detects the available joysticks / gamepads on the computer
* and return them in a list.
*
* @return List of available joysticks / gamepads connected to the computer
*/
private static Controller[] getAvailablePadControllers() {
List<Controller> gameControllers = new ArrayList<Controller>();
// Get a list of the controllers JInput knows about and can interact
// with
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
// Check the useable controllers (gamepads or joysticks with at least 2
// axis and 2 buttons)
for (Controller controller : controllers) {
if ((controller.getType() == Controller.Type.GAMEPAD) || (controller.getType() == Controller.Type.STICK)) {
int nbOfAxis = 0;
// Get this controllers components (buttons and axis)
Component[] components = controller.getComponents();
// Check the availability of X/Y axis and at least 2 buttons
// (for A and B, because select and start can use the keyboard)
for (Component component : components) {
if ((component.getIdentifier() == Component.Identifier.Axis.X)
|| (component.getIdentifier() == Component.Identifier.Axis.Y)) {
nbOfAxis++;
}
}
if ((nbOfAxis >= 2) && (getButtons(controller).length >= 2)) {
// Valid game controller
gameControllers.add(controller);
}
}
}
return gameControllers.toArray(new Controller[0]);
}
示例4: getButtons
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* Return the available buttons on this controller (by priority order).
*
* @param controller
* @return
*/
private static Component[] getButtons(Controller controller) {
List<Component> buttons = new ArrayList<Component>();
// Get this controllers components (buttons and axis)
Component[] components = controller.getComponents();
for (Component component : components) {
if (component.getIdentifier() instanceof Component.Identifier.Button) {
buttons.add(component);
}
}
return buttons.toArray(new Component[0]);
}
示例5: getAvailablePadControllers
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* This method detects the available joysticks / gamepads on the computer
* and return them in a list.
*
* @return List of available joysticks / gamepads connected to the computer
*/
private static Controller[] getAvailablePadControllers() {
List<Controller> gameControllers = new ArrayList<>();
// Get a list of the controllers JInput knows about and can interact
// with
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
// Check the useable controllers (gamepads or joysticks with at least 2
// axis and 2 buttons)
for (Controller controller : controllers) {
if ((controller.getType() == Controller.Type.GAMEPAD) || (controller.getType() == Controller.Type.STICK)) {
int nbOfAxis = 0;
// Get this controllers components (buttons and axis)
Component[] components = controller.getComponents();
// Check the availability of X/Y axis and at least 2 buttons
// (for A and B, because select and start can use the keyboard)
for (Component component : components) {
if ((component.getIdentifier() == Component.Identifier.Axis.X)
|| (component.getIdentifier() == Component.Identifier.Axis.Y)) {
nbOfAxis++;
}
}
if ((nbOfAxis >= 2) && (getButtons(controller).length >= 2)) {
// Valid game controller
gameControllers.add(controller);
}
}
}
return gameControllers.toArray(new Controller[0]);
}
示例6: getButtons
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* Return the available buttons on this controller (by priority order).
*/
private static Component[] getButtons(Controller controller) {
List<Component> buttons = new ArrayList<>();
// Get this controllers components (buttons and axis)
Component[] components = controller.getComponents();
for (Component component : components) {
if (component.getIdentifier() instanceof Component.Identifier.Button) {
buttons.add(component);
}
}
return buttons.toArray(new Component[0]);
}
示例7: getComponents
import net.java.games.input.Component; //导入方法依赖的package包/类
/**
* Store the indices for the analog sticks axes (x,y) and (z,rz), POV hat,
* and button components of the controller.
*/
public HashMap<String, Integer> getComponents() {
HashMap<String, Integer> ret = new HashMap<String, Integer>();
if (controller == null) {
error("no controller set");
return ret;
}
components = controller.getComponents();
if (components.length == 0) {
error("No Components found");
return ret;
} else {
info("Num. Components: " + components.length);
}
Component c;
for (int i = 0; i < components.length; i++) {
c = components[i];
Identifier id = c.getIdentifier();
if (id instanceof Component.Identifier.Axis) {
}
ret.put(c.getIdentifier().toString(), i);
}
// substitutions
for (Map.Entry<String, String> entry : mapIds.entrySet()) {
String from = entry.getKey();
String to = entry.getValue();
if (ret.containsKey(from)) {
Integer move = ret.get(from);
ret.put(mapIds.get(from), move);
}
}
// get the indices for the axes of the analog sticks: (x,y) and (z,rz)
xAxisIdx = findCompIndex(components, Component.Identifier.Axis.X, "x-axis");
yAxisIdx = findCompIndex(components, Component.Identifier.Axis.Y, "y-axis");
zAxisIdx = findCompIndex(components, Component.Identifier.Axis.Z, "z-axis");
rzAxisIdx = findCompIndex(components, Component.Identifier.Axis.RZ, "rz-axis");
// get POV hat index
povIdx = findCompIndex(components, Component.Identifier.Axis.POV, "POV hat");
findButtons(components);
return ret;
}
示例8: eventQueueLoop
import net.java.games.input.Component; //导入方法依赖的package包/类
private Runnable eventQueueLoop() {
return new Runnable() {
@Override
public void run() {
if (gameController != null) {
Event event = new Event();
while (!Thread.interrupted()) {
gameController.poll();
EventQueue queue = gameController.getEventQueue();
while (queue.getNextEvent(event)) {
Component component = event.getComponent();
if (component.getIdentifier() == Component.Identifier.Axis.X) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT7;//left on, right off
gamepadbyte &= ~BIT6;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT6;
gamepadbyte &= ~BIT7;
} else {
gamepadbyte &= ~(BIT7 | BIT6);
}
} else if (component.getIdentifier() == Component.Identifier.Axis.Y) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT5;//up on, down off
gamepadbyte &= ~BIT4;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT4;//down on, up off
gamepadbyte &= ~BIT5;
} else {
gamepadbyte &= ~(BIT4 | BIT5);
}
} else if (component == buttons[0]) {
if (isPressed(event)) {
gamepadbyte |= BIT0;
} else {
gamepadbyte &= ~BIT0;
}
} else if (component == buttons[1]) {
if (isPressed(event)) {
gamepadbyte |= BIT1;
} else {
gamepadbyte &= ~BIT1;
}
} else if (component == buttons[2]) {
if (isPressed(event)) {
gamepadbyte |= BIT2;
} else {
gamepadbyte &= ~BIT2;
}
} else if (component == buttons[3]) {
if (isPressed(event)) {
gamepadbyte |= BIT3;
} else {
gamepadbyte &= ~BIT3;
}
}
}
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
}
};
}
示例9: eventQueueLoop
import net.java.games.input.Component; //导入方法依赖的package包/类
private Runnable eventQueueLoop() {
return new Runnable() {
@Override
public void run() {
if (gameController != null) {
Event event = new Event();
while (!Thread.interrupted()) {
gameController.poll();
EventQueue queue = gameController.getEventQueue();
while (queue.getNextEvent(event)) {
Component component = event.getComponent();
if (component.getIdentifier() == Component.Identifier.Axis.X) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT7;//left on, right off
gamepadbyte &= ~BIT6;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT6;
gamepadbyte &= ~BIT7;
} else {
gamepadbyte &= ~(BIT7 | BIT6);
}
} else if (component.getIdentifier() == Component.Identifier.Axis.Y) {
if (event.getValue() > threshold) {
gamepadbyte |= BIT5;//up on, down off
gamepadbyte &= ~BIT4;
} else if (event.getValue() < -threshold) {
gamepadbyte |= BIT4;//down on, up off
gamepadbyte &= ~BIT5;
} else {
gamepadbyte &= ~(BIT4 | BIT5);
}
} else if (component == buttons[0]) {
if (isPressed(event)) {
gamepadbyte |= BIT0;
} else {
gamepadbyte &= ~BIT0;
}
} else if (component == buttons[1]) {
if (isPressed(event)) {
gamepadbyte |= BIT1;
} else {
gamepadbyte &= ~BIT1;
}
} else if (component == buttons[2]) {
if (isPressed(event)) {
gamepadbyte |= BIT2;
} else {
gamepadbyte &= ~BIT2;
}
} else if (component == buttons[3]) {
if (isPressed(event)) {
gamepadbyte |= BIT3;
} else {
gamepadbyte &= ~BIT3;
}
}
}
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// Preserve interrupt status
Thread.currentThread().interrupt();
}
}
}
}
};
}