docs: Fixed bugs in Game Controller training doc.
bug: 16375247, 14671463 Change-Id: I51f595065435c3990a979a66b402acc2b6867a1a
This commit is contained in:
@@ -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
|
{@link android.app.Activity} or focused {@link android.view.View} (you should
|
||||||
implement the callbacks for either the {@link android.app.Activity} or
|
implement the callbacks for either the {@link android.app.Activity} or
|
||||||
{@link android.view.View}, but not both): </p>
|
{@link android.view.View}, but not both): </p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>From {@link android.app.Activity}:
|
<li>From {@link android.app.Activity}:
|
||||||
<ul>
|
<ul>
|
||||||
<li>{@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent) dispatchGenericMotionEvent(android.view.MotionEvent)}
|
<li>{@link android.app.Activity#dispatchGenericMotionEvent(android.view.MotionEvent)
|
||||||
|
dispatchGenericMotionEvent(android.view. MotionEvent)}
|
||||||
<p>Called to process generic motion events such as joystick movements.</p>
|
<p>Called to process generic motion events such as joystick movements.</p>
|
||||||
</li>
|
</li>
|
||||||
<li>{@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent) dispatchKeyEvent(android.view.KeyEvent)}
|
<li>{@link android.app.Activity#dispatchKeyEvent(android.view.KeyEvent)
|
||||||
|
dispatchKeyEvent(android.view.KeyEvent)}
|
||||||
<p>Called to process key events such as a press or release of a
|
<p>Called to process key events such as a press or release of a
|
||||||
gamepad or D-pad button.</p>
|
gamepad or D-pad button.</p>
|
||||||
</li>
|
</li>
|
||||||
@@ -244,16 +245,18 @@ buttons.</p>
|
|||||||
and {@link android.view.KeyEvent#KEYCODE_MENU}<sup>*</sup></td>
|
and {@link android.view.KeyEvent#KEYCODE_MENU}<sup>*</sup></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Same as Android <em>Back</em></td>
|
<td>Same as Android <em>Back</em> navigation behavior described in the
|
||||||
|
<a href="{@docRoot}design/patterns/navigation.html">Navigation</a> design
|
||||||
|
guide.</td>
|
||||||
<td>{@link android.view.KeyEvent#KEYCODE_BACK KEYCODE_BACK}</td>
|
<td>{@link android.view.KeyEvent#KEYCODE_BACK KEYCODE_BACK}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Navigate back to a previous item in a menu</td>
|
<td>Navigate back to a previous item in a menu</td>
|
||||||
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B}<sup>**</sup></td>
|
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Confirm selection, or perform primary game action</td>
|
<td>Confirm selection, or perform primary game action</td>
|
||||||
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}<sup>**</sup> and
|
<td>{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} and
|
||||||
{@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER}</td>
|
{@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -261,10 +264,6 @@ buttons.</p>
|
|||||||
<em>* Your game should not rely on the presence of the Start, Select, or Menu
|
<em>* Your game should not rely on the presence of the Start, Select, or Menu
|
||||||
buttons.</em>
|
buttons.</em>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
|
||||||
<em>** This could be the opposite button (A/B), depending on the locale that
|
|
||||||
you are supporting.</em>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p class="note"><strong>Tip: </strong>Consider providing a configuration screen
|
<p class="note"><strong>Tip: </strong>Consider providing a configuration screen
|
||||||
in your game to allow users to personalize their own game controller mappings for
|
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) {
|
private static boolean isFireKey(int keyCode) {
|
||||||
// Here we treat Button_A and DPAD_CENTER as the primary action
|
// 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
|
// keys for the game.
|
||||||
// DPAD_CENTER depending on the user expectations for the locale
|
|
||||||
// in which your game runs.
|
|
||||||
return keyCode == KeyEvent.KEYCODE_DPAD_CENTER
|
return keyCode == KeyEvent.KEYCODE_DPAD_CENTER
|
||||||
|| keyCode == KeyEvent.KEYCODE_BUTTON_A;
|
|| keyCode == KeyEvent.KEYCODE_BUTTON_A;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p>Follow these best practices when handling button presses:</p>
|
<p class="note"><strong>Note: </strong>On Android 4.2 (API
|
||||||
<ul>
|
|
||||||
<li><strong>Provide localized button mappings.</strong> Generally, if your game
|
|
||||||
has a primary gameplay action (for example, it fires lasers, lets your avatar
|
|
||||||
do a high jump, or confirms an item selection), you should map
|
|
||||||
both {@link android.view.KeyEvent#KEYCODE_DPAD_CENTER DPAD_CENTER} and
|
|
||||||
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to this action. However,
|
|
||||||
in some locales, users may expect
|
|
||||||
{@link android.view.KeyEvent#KEYCODE_BUTTON_B BUTTON_B} to be the confirm
|
|
||||||
button and {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} to be the
|
|
||||||
back button instead. If you are supporting these locales, make sure to treat
|
|
||||||
the A and B buttons accordingly in your game. To determine the user's locale,
|
|
||||||
call the {@link java.util.Locale#getDefault()} method.
|
|
||||||
<li><strong>Map {@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A}
|
|
||||||
consistently across different Android versions.</strong> On Android 4.2 (API
|
|
||||||
level 17) and lower, the system treats
|
level 17) and lower, the system treats
|
||||||
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the Android
|
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the Android
|
||||||
<em>Back</em> key by default. If your app supports these Android
|
<em>Back</em> key by default. If your app supports these Android
|
||||||
versions, make sure to treat
|
versions, make sure to treat
|
||||||
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the primary game
|
{@link android.view.KeyEvent#KEYCODE_BUTTON_A BUTTON_A} as the primary game
|
||||||
action (except in the localization case mentioned
|
action. To determine the current Android SDK
|
||||||
above). To determine the current Android SDK
|
|
||||||
version on the device, refer to the
|
version on the device, refer to the
|
||||||
{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.
|
{@link android.os.Build.VERSION#SDK_INT Build.VERSION.SDK_INT} value.</p>
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h2 id="dpad">Process Directional Pad Input</h2>
|
<h2 id="dpad">Process Directional Pad Input</h2>
|
||||||
<p>The 4-way directional pad (D-pad) is a common physical control in many game
|
<p>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.
|
// UP and DOWN direction accordingly.
|
||||||
else if (Float.compare(yaxis, -1.0f) == 0) {
|
else if (Float.compare(yaxis, -1.0f) == 0) {
|
||||||
directionPressed = Dpad.UP;
|
directionPressed = Dpad.UP;
|
||||||
} else if (Float.compare(yaxis, -1.0f) == 0) {
|
} else if (Float.compare(yaxis, 1.0f) == 0) {
|
||||||
directionPressed = Dpad.DOWN;
|
directionPressed = Dpad.DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user