diff --git a/docs/html/training/game-controllers/controller-input.jd b/docs/html/training/game-controllers/controller-input.jd index c9517ba1dbd78..25fcde4ae5c18 100644 --- a/docs/html/training/game-controllers/controller-input.jd +++ b/docs/html/training/game-controllers/controller-input.jd @@ -39,14 +39,15 @@ these input events by implementing the following callback methods in your active {@link android.app.Activity} or focused {@link android.view.View} (you should implement the callbacks for either the {@link android.app.Activity} or {@link android.view.View}, but not both):
-Called to process generic motion events such as joystick movements.
Called to process key events such as a press or release of a gamepad or D-pad button.
-** This could be the opposite button (A/B), depending on the locale that -you are supporting. -
Tip: Consider providing a configuration screen in your game to allow users to personalize their own game controller mappings for @@ -309,41 +308,22 @@ public class GameView extends View { private static boolean isFireKey(int keyCode) { // Here we treat Button_A and DPAD_CENTER as the primary action - // keys for the game. You may need to switch this to Button_B and - // DPAD_CENTER depending on the user expectations for the locale - // in which your game runs. + // keys for the game. return keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_BUTTON_A; } } -
Follow these best practices when handling button presses:
-Note: On Android 4.2 (API level 17) and lower, the system treats {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the Android Back key by default. If your app supports these Android versions, make sure to treat {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the primary game -action (except in the localization case mentioned -above). To determine the current Android SDK +action. To determine the current Android SDK version on the device, refer to the -{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value. -
The 4-way directional pad (D-pad) is a common physical control in many game @@ -424,7 +404,7 @@ public class Dpad { // UP and DOWN direction accordingly. else if (Float.compare(yaxis, -1.0f) == 0) { directionPressed = Dpad.UP; - } else if (Float.compare(yaxis, -1.0f) == 0) { + } else if (Float.compare(yaxis, 1.0f) == 0) { directionPressed = Dpad.DOWN; } }