No hay resultados
Now that we have game controllers handled, let’s take a closer look at how to set up your Amazon Fire TV game for use with the Fire TV remote.
The Fire TV remote control is available with and without the microphone and voice search button, but since that is reserved for the system both remotes expose the same keys for use by apps.
The circular d-pad on the remote control is accessed in the same way as the game controller d-pad.
if(gamepad_button_check(global.gamepad,gp_padu)) { // move up }
The select button in the center of the d-pad sends the vk_space keycode.
if(keyboard_check(vk_space) { // d-pad center action button is being pressed }
When designing your input scheme for the remote control, you may want to consider the player holding the remote sideways. This provides more of a gamepad feel. If you use this approach, you will need to provide guidance to the player about how to hold the remote and you will need to translate the d-pad controls in your code (such as treating gp_padl as down and gp_padd as right, etc.).
Just as with the game controller, above, the remote control media and the Back buttons are detected as keyboard key actions as described in the Game Controller section, in our previous post.
While the Home button is detectable as a keyboard key action, the button has a defined behavior on Amazon Fire TV so it is recommended that you do not override this behavior in your app. Doing so will result in your app submission failing the Amazon technical review process.
The Voice/Search button is not accessible to application code.
When building a GameMaker: Studio game for the PC, it is common to assume that gamepad ID 1 is, in fact, a gamepad. On the Amazon Fire TV this is not likely the case. Many Amazon Fire TV devices will have the remote control paired, even if there are one or more additional game controllers (or even additional remotes) paired. As a developer, you should not make assumptions about the number, order or type of controllers you will discover in the System event.
If you are building a game that can be played either with the remote control or the game controller, you will need to provide some way to indicate which controller is currently active and a way to switch between them. You might consider tailoring the instructions, on-screen buttons and help screens to the type of controller being used.
This code uses the Play/Pause button to switch between controllers. In your game, you’ll need to consider where the user can change controller types, such as only in the settings menu or title screen, and what controls are used to make the change.
// toggle gamepad with play/pause direction if(gamepad_is_connected(1) && gamepad_is_connected(2)) { // toggle remote/gamepad with Play/Pause button if(keyboard_check_pressed(ord("U"))) { if(global.gamepad==1) global.gamepad=2; else global.gamepad=1; if(string_pos("emote", gamepad_get_description(global.gamepad)) !=0) controllerType = 2; if(string_pos("ontroller", gamepad_get_description(global.gamepad)) !=0) controllerType = 1; } }
You can use code like this to indicate the current selection:
// Multiple controller switching UI if(gamepad_is_connected(1) && gamepad_is_connected(2) && controllerType > 0) { draw_text(610,640, "Play/Pause to switch controller"); draw_sprite_ext(sprController, 0, room_width-80, room_height-40, 0.75, 0.75, 0, c_white, 1); draw_sprite_ext(sprRemote, 0, room_width-129, room_height-40, 1, 1, 0, c_white, 1); if (controllerType == 1) draw_rectangle(room_width-80-34, room_height-40-22, room_width-80+34, room_height-40+22, true); else draw_rectangle(room_width-129-15, room_height-40-22, room_width-129+15, room_height-40+22, true); }
This code shows icons for the remote and game controller and draws a rectangle around the currently selected controller. Now that we’ve covered the basics for game controllers and the Fire TV remote controller, we are ready to move on to our final topics: in-app purchasing and GameCircle. See you next week!
Part 2: Basic Controller Detection