- Mastering Android Game Development
- Raul Portales
- 233字
- 2021-07-16 13:59:10
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.
- MySQL 8從入門到精通(視頻教學版)
- Effective C#:改善C#代碼的50個有效方法(原書第3版)
- 看透JavaScript:原理、方法與實踐
- Mastering JBoss Enterprise Application Platform 7
- iOS開發實戰:從入門到上架App Store(第2版) (移動開發叢書)
- 批調度與網絡問題的組合算法
- TMS320LF240x芯片原理、設計及應用
- Xamarin Cross-Platform Development Cookbook
- 算法超簡單:趣味游戲帶你輕松入門與實踐
- Python面向對象編程(第4版)
- iOS Application Development with OpenCV 3
- 架構師應該知道的37件事
- Game Physics Cookbook
- ATmega16單片機C語言程序設計經典實例
- INSTANT Fancybox