9.1 configuration and query of Libgdx input processing, 9.1 libgdx

Source: Internet
Author: User
Tags libgdx

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.