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


Java Controller.Type方法代码示例

本文整理汇总了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;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:23,代码来源:YassInput.java

示例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();
        }
    }
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:21,代码来源:YassInput.java

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

示例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);
}
 
开发者ID:RobotsByTheC,项目名称:JDriverStation,代码行数:14,代码来源:JoystickManager.java

示例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));
                }
            }
        }
    });
}
 
开发者ID:RobotsByTheC,项目名称:JDriverStation,代码行数:66,代码来源:JoystickManager.java


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