public class RemoteInput extends Object implements Runnable, Input
An Input
implementation that receives touch, key, accelerometer and compass events from a remote Android device. Just
instantiate it and specify the port it should listen on for incoming connections (default 8190). Then store the new RemoteInput
instance in Gdx.input. That's it.
On your Android device you can use the gdx-remote application available on the Google Code page as an APK or in SVN (extensions/gdx-remote). Open it, specify the IP address and the port of the PC your libgdx app is running on and then tap away.
The touch coordinates will be translated to the desktop window's coordinate system, no matter the orientation of the device
Modifier and Type | Class and Description |
---|---|
static interface |
RemoteInput.RemoteInputListener |
Input.Buttons, Input.Keys, Input.Orientation, Input.Peripheral, Input.TextInputListener
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT |
String[] |
ips |
Constructor and Description |
---|
RemoteInput() |
RemoteInput(int port) |
RemoteInput(int port,
RemoteInput.RemoteInputListener listener) |
RemoteInput(RemoteInput.RemoteInputListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
cancelVibrate()
Stops the vibrator
|
float |
getAccelerometerX() |
float |
getAccelerometerY() |
float |
getAccelerometerZ() |
float |
getAzimuth()
The azimuth is the angle of the device's orientation around the z-axis.
|
long |
getCurrentEventTime() |
int |
getDeltaX() |
int |
getDeltaX(int pointer) |
int |
getDeltaY() |
int |
getDeltaY(int pointer) |
InputProcessor |
getInputProcessor() |
String[] |
getIPs() |
Input.Orientation |
getNativeOrientation() |
float |
getPitch()
The pitch is the angle of the device's orientation around the x-axis.
|
float |
getRoll()
The roll is the angle of the device's orientation around the y-axis.
|
int |
getRotation() |
void |
getRotationMatrix(float[] matrix)
Returns the rotation matrix describing the devices rotation as per SensorManager#getRotationMatrix(float[], float[], float[], float[]).
|
void |
getTextInput(Input.TextInputListener listener,
String title,
String text,
String hint)
System dependent method to input a string of text.
|
int |
getX() |
int |
getX(int pointer)
Returns the x coordinate in screen coordinates of the given pointer.
|
int |
getY() |
int |
getY(int pointer)
Returns the y coordinate in screen coordinates of the given pointer.
|
boolean |
isButtonPressed(int button)
Whether a given button is pressed or not.
|
boolean |
isCatchBackKey() |
boolean |
isConnected() |
boolean |
isCursorCatched() |
boolean |
isKeyJustPressed(int key)
Returns whether the key has just been pressed.
|
boolean |
isKeyPressed(int key)
Returns whether the key is pressed.
|
boolean |
isPeripheralAvailable(Input.Peripheral peripheral)
Queries whether a
Input.Peripheral is currently available. |
boolean |
isTouched() |
boolean |
isTouched(int pointer)
Whether the screen is currently touched by the pointer with the given index.
|
boolean |
justTouched() |
void |
run() |
void |
setCatchBackKey(boolean catchBack)
Sets whether the BACK button on Android should be caught.
|
void |
setCatchMenuKey(boolean catchMenu)
Sets whether the MENU button on Android should be caught.
|
void |
setCursorCatched(boolean catched)
Only viable on the desktop.
|
void |
setCursorImage(Pixmap pixmap,
int xHotspot,
int yHotspot)
Only viable on the desktop.
|
void |
setCursorPosition(int x,
int y)
Only viable on the desktop.
|
void |
setInputProcessor(InputProcessor processor)
Sets the
InputProcessor that will receive all touch and key input events. |
void |
setOnscreenKeyboardVisible(boolean visible)
Sets the on-screen keyboard visible if available.
|
void |
vibrate(int milliseconds)
Vibrates for the given amount of time.
|
void |
vibrate(long[] pattern,
int repeat)
Vibrate with a given pattern.
|
public static int DEFAULT_PORT
public final String[] ips
public RemoteInput()
public RemoteInput(RemoteInput.RemoteInputListener listener)
public RemoteInput(int port)
public RemoteInput(int port, RemoteInput.RemoteInputListener listener)
public boolean isConnected()
public float getAccelerometerX()
getAccelerometerX
in interface Input
public float getAccelerometerY()
getAccelerometerY
in interface Input
public float getAccelerometerZ()
getAccelerometerZ
in interface Input
public int getX()
public int getX(int pointer)
Input
public int getY()
public int getY(int pointer)
Input
public boolean isTouched()
public boolean justTouched()
justTouched
in interface Input
public boolean isTouched(int pointer)
Input
public boolean isButtonPressed(int button)
Input
Input.Buttons
. On Android only the Button#LEFT
constant is meaningful before version 4.0.isButtonPressed
in interface Input
button
- the button to check.public boolean isKeyPressed(int key)
Input
isKeyPressed
in interface Input
key
- The key code as found in Input.Keys
.public boolean isKeyJustPressed(int key)
Input
isKeyJustPressed
in interface Input
key
- The key code as found in Input.Keys
.public void getTextInput(Input.TextInputListener listener, String title, String text, String hint)
Input
Input.TextInputListener
will be called on the rendering
thread.getTextInput
in interface Input
listener
- The TextInputListener.title
- The title of the text input dialog.text
- The message presented to the user.public void setOnscreenKeyboardVisible(boolean visible)
Input
setOnscreenKeyboardVisible
in interface Input
visible
- visible or notpublic void vibrate(int milliseconds)
Input
in your manifest file in order for this to work.public void vibrate(long[] pattern, int repeat)
Input
public void cancelVibrate()
Input
cancelVibrate
in interface Input
public float getAzimuth()
Input
getAzimuth
in interface Input
public float getPitch()
Input
getPitch
in interface Input
public float getRoll()
Input
getRoll
in interface Input
public void setCatchBackKey(boolean catchBack)
Input
setCatchBackKey
in interface Input
catchBack
- whether to catch the back buttonpublic boolean isCatchBackKey()
isCatchBackKey
in interface Input
public void setInputProcessor(InputProcessor processor)
Input
InputProcessor
that will receive all touch and key input events. It will be called before the
ApplicationListener.render()
method each frame.setInputProcessor
in interface Input
processor
- the InputProcessorpublic InputProcessor getInputProcessor()
getInputProcessor
in interface Input
InputProcessor
or null.public String[] getIPs()
RemoteSender
or gdx-remote should connect to. Most likely the LAN addresses if behind a NAT.public boolean isPeripheralAvailable(Input.Peripheral peripheral)
Input
Input.Peripheral
is currently available. In case of Android and the Input.Peripheral.HardwareKeyboard
this returns the whether the keyboard is currently slid out or not.isPeripheralAvailable
in interface Input
peripheral
- the Input.Peripheral
public int getRotation()
getRotation
in interface Input
public Input.Orientation getNativeOrientation()
getNativeOrientation
in interface Input
public void setCursorCatched(boolean catched)
Input
setCursorCatched
in interface Input
catched
- whether to catch or not to catch the mouse cursorpublic boolean isCursorCatched()
isCursorCatched
in interface Input
public int getDeltaX()
public int getDeltaX(int pointer)
public int getDeltaY()
public int getDeltaY(int pointer)
public void setCursorPosition(int x, int y)
Input
setCursorPosition
in interface Input
x
- the x-positiony
- the y-positionpublic void setCursorImage(Pixmap pixmap, int xHotspot, int yHotspot)
Input
Pixmap
. The Pixmap must be in RGBA8888 format, width & height must be powers-of-two
greater than zero (not necessarily equal), and alpha transparency must be single-bit (i.e., 0x00 or 0xFF only). To revert to
the default operating system cursor, pass in a null Pixmap; xHotspot & yHotspot are ignored in this case.setCursorImage
in interface Input
pixmap
- the mouse cursor image as a Pixmap
, or null to revert to the default
operating system cursorxHotspot
- the x location of the hotspot pixel within the cursor image (origin top-left corner)yHotspot
- the y location of the hotspot pixel within the cursor image (origin top-left corner)public void setCatchMenuKey(boolean catchMenu)
Input
setCatchMenuKey
in interface Input
catchMenu
- whether to catch the menu buttonpublic long getCurrentEventTime()
getCurrentEventTime
in interface Input
InputProcessor
.public void getRotationMatrix(float[] matrix)
Input
getRotationMatrix
in interface Input
Copyright © 2015. All rights reserved.