Game Development Reference
In-Depth Information
Log.d(TAG, "Button Event: " + payload + " Type: " + type + " Btn:"
+ button);
}
/**
* Nunchuck handler
* @param payload String of the form
* JANGLE=xx.x|JMAGNITUDE=xx
*/
private static void handleNunchuckEvent(Properties payload) {
try {
/**
* The angle \a ang is relative to the positive y-axis into quadrant I and
* ranges from 0 to 360 degrees. The magnitude is the distance from the
* center to where the joystick is being held.
*/
float joyAngle = Float.parseFloat(payload.getProperty("JANGLE"));
float joyMagnitude = Float.parseFloat(payload
.getProperty("JMAGNITUDE"));
if (joyAngle == Float.NaN || joyMagnitude < 0.4) {
return;
}
if (mListener != null) {
mListener.onJoystickEvent(joyAngle, joyMagnitude);
}
} catch (NumberFormatException e) {
Log.e(TAG, "Nunchuck parse error:" + e);
}
}
In Listing 8-2 you can see the way event data is encoded in the message payload. For
example,
When the A button is pressed on the Wiimote, the OnEvent method fires
with the payload.
EVT_TYPE=BTNPRESS|BTN=A
Similarly, when it is released, you will receive
EVT_TYPE=BTNRELEASE|BTN=A
When the Nunchuck is inserted, you will receive
EVT_TYPE=EXT_INSERTED|EXT_NAME=Nunchuk
And finally, when the joystick in the Nunchuk is moved, you will receive
EVT_TYPE= NUNCHUK|JANGLE=<Angle in degrees>|JMAGNITUDE=<Stick magnitude [0..1]>
 
Search WWH ::




Custom Search