当前位置: 首页>>代码示例>>Java>>正文


Java Component.getIdentifier方法代码示例

本文整理汇总了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 ++;
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:JInputJoyInput.java

示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:18,代码来源:Joystick.java

示例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]);
}
 
开发者ID:kostkol87,项目名称:Nes-emulator,代码行数:35,代码来源:ControllerImpl.java

示例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]);
}
 
开发者ID:kostkol87,项目名称:Nes-emulator,代码行数:18,代码来源:ControllerImpl.java

示例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]);
}
 
开发者ID:andrew-hoffman,项目名称:halfnes,代码行数:35,代码来源:ControllerImpl.java

示例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]);
}
 
开发者ID:andrew-hoffman,项目名称:halfnes,代码行数:15,代码来源:ControllerImpl.java

示例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;
}
 
开发者ID:glaudiston,项目名称:project-bianca,代码行数:54,代码来源:Joystick.java

示例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();
                    }
                }
            }
        }
    };
}
 
开发者ID:kostkol87,项目名称:Nes-emulator,代码行数:72,代码来源:ControllerImpl.java

示例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();
                    }
                }
            }
        }
    };
}
 
开发者ID:andrew-hoffman,项目名称:halfnes,代码行数:71,代码来源:ControllerImpl.java


注:本文中的net.java.games.input.Component.getIdentifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。