官术网_书友最值得收藏!

Selecting control modes

It is common for games to ask the user to select the control mode they prefer, but it is also a good practice to avoid friction as much as possible by not asking what is not necessary.

YASS is only using a virtual joystick and the gamepad controls. There is no need to ask the user which one he or she wants. Both input modes are compatible, especially because the virtual joystick does not display anything on the screen when it is not used. The only thing we need to do is to modify the GameEngine to support more than one InputController.

Note

We will support both input modes simultaneously.

The way to support both input modes at the same time is to create a CompositeInputController that uses the composition pattern to have both a VirtualJoystickInputController and a GamepadInputController, and combines the input from both.

To synchronize the readings from the two input controllers, we are going to use a method on the InputController called onPreUpdate, which will be called just before onUpdate. We will use it to populate the values of mHorizontalFactor, mVerticalFactor, and mIsFiring with the ones read from the other controllers.

public void onPreUpdate() {
  mIsFiring = mGamepadInputController.mIsFiring || mVJoystickInputController.mIsFiring;
  mHorizontalFactor = mGamepadInputController.mHorizontalFactor + mVJoystickInputController.mHorizontalFactor;
  mVerticalFactor = mGamepadInputController.mVerticalFactor + mVJoystickInputController.mVerticalFactor;
}

We now have a game that can be controlled with a virtual joystick and a gamepad.

主站蜘蛛池模板: 慈溪市| 佳木斯市| 泸水县| 措美县| 苗栗市| 宜阳县| 天气| 梅河口市| 平陆县| 留坝县| 长春市| 天峨县| 集安市| 监利县| 岫岩| 磐安县| 惠东县| 轮台县| 阜城县| 自治县| 汽车| 柳林县| 镇安县| 扎囊县| 凌云县| 岐山县| 盈江县| 东兰县| 安达市| 建瓯市| 庄河市| 蚌埠市| 阜阳市| 库伦旗| 聂拉木县| 彝良县| 鹤岗市| 南通市| 正宁县| 江北区| 高平市|