9.1 configuration and query of Libgdx input processing, 9.1 libgdx
(Official Website: www.libgdx.cn)
Sometimes it is necessary to determine whether the input device is supported. Generally, your game does not need to support all input devices. For example, you may not need an accelerometer or a compass. In this case, we need to disable these devices to maintain power. Next we will teach you how to do this.
Disable accelerometer and compass (Android)
Before executing the AndroidApplication. initialize () method, you can use the AndroidApplicationConfiguration class to set some parameters, including configuring the input device.
Assume that our games do not require accelerometer and compass, we can disable these devices:
Public class MyGameActivity extends AndroidApplication {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration ();
Config. useAccelerometer = false;
Config. useCompass = false;
Initialize (new MyGame (), config );
}
}
By default, both the accelerometer and the compass are enabled, and the above Code can disable them.
Query available input devices
To check whether the Input device is available on the current platform, you can use the Input. isPeripheraAvailable () method.
Boolean hardwareKeyboard = Gdx. input. isPeripheralAvailable (Peripheral. HardwareKeyboard );
Boolean multiTouch = Gdx. input. isPeripheralAvailable (Peripheral. MultitouchScreen );
Note that only some Android devices have a real keyboard.
(Www.libgdx.cn is copyrighted. If you need to reprint it, indicate the source)