And now half of the time until christmas is over.
Today we will deal with the hardware, that is just avaiable for android devices, but still easily accessable via libgdx.
hardware-keys
Most android-smartphones have hardware-keys like menu,back or the volume-keys. By default the back-keys is causing the quit of the app and if you press the menu-key for a longer time a on-screen keyboard is called. If you want to define your own actions for these keys, you have to suppress the default reaction:
Gdx.input.setCatchBackKey(true);
Gdx.input.setCatchMenuKey(true);
// [...]
if (Gdx.input.isKeyPressed(Keys.BACK) || Gdx.input.isKeyPressed(Keys.MENU)){
accelerometer
Many android-smartphone have an accelerometer. You can find out how your android-device is orientated in the air.
If you are only interested in the rough orientation, you can call this (possible values: 0,90,180,270):
int orientation = Gdx.input.getOrientation();
You can as well get the detailed values on the axis.
if( Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer) ){
float accelX = Gdx.input.getAccelerometerX();
float accelY = Gdx.input.getAccelerometerY();
float accelZ = Gdx.input.getAccelerometerZ();
}
compass
if(Gdx.input.isPeripheralAvailable(Peripheral.Compass)){
float azimuth = Gdx.input.getAzimuth();
float pitch = Gdx.input.getPitch();
float roll = Gdx.input.getRoll();
}
The angles are given in degrees.
vibrator
To use the extremly important vibrator, you have to add the android.permission.VIBRATE permission.(more info)
Now we can either let the vibrator vibrate for one second…
Gdx.input.vibrate(1000);
… or we let him vibrate for 200 milliseconds, that stop for 400 milliseconds and then again turn on for 300 milliseconds.
Gdx.input.vibrate(new long[] { 0, 200, 400, 300}, -1);
I have no idea, what you could use this for sencefully.
cursor
In the desktop-version you sometimes want to catch the cursor in the center of your window. (often used with 3D-game with ego-perspective)
Gdx.input.setCursorCatched(true);
And we can set the cursor to a certain position.
Gdx.input.setCursorPosition(x, y);
I still have a few things planeed for the rest of the time (like collisions), but it is ar from enough stuff to write.
So if you’re missing something, want to know something or know features of libgdx, that I should know, write a comment!
So if you’re missing something, want to know something or know features of libgdx, that I should know, write a comment!
No comments:
Post a Comment