Game Development Reference
In-Depth Information
/************************************************
* ZEEMOTE BUTTON EVENTS
************************************************/
public void buttonPressed(ButtonEvent event) {
int b = event.getButtonID();
String label = event.getController().getConfiguration().getButtonLabel(b);
}
public void buttonReleased(ButtonEvent event) {
String buttonName = event.getController().getConfiguration()
.getButtonLabel(event.getButtonID());
}
/************************************************
* ZEEMOTE JOYSTIC EVENT
************************************************/
public void joystickMoved(JoystickEvent e) {
// A joystick moved. Scale the values between -100 and 100
int x = e.getScaledX(-100, 100);
int y = e.getScaledY(-100, 100);
Log.d(TAG, "X=" + x + ",Y=" + y);
}
}
To connect to the Zeemote from your app activity, call the connect method of the Zeemote
class, like so:
Zeemote zee = new Zeemote(this);
zee.connect();
When the connect method fires, the Zeemote connection UI will take over and allow you
to connect (if the controller is on and close to the phone). As a bonus, you can check
programmatically if Bluetooth is enabled using BluetoothAdapter.getDefaultAdapter() , and
if not enabled, use the built-in Android UI to do it (see Listing 8-15).
Listing 8-15. Enabling the Bluetooth Adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
// Enable it
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
ctx.startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
You can now easily integrate the Wiimote and Zeemote into your mobile game.
 
Search WWH ::




Custom Search