Last week we covered some of the missing documentation in GameMaker with respect to Amazon Fire TV, detailing what you need to know about basic controller detection. This week, as we continue on my building Retroids journey, we will take a closer look at handling controllers.
A well behaved game should handle controllers coming and going during play. This covers cases where a controller loses connectivity due to range or interference, or if the batteries in the controller die while playing.
To accomplish this, the above code needs to be present in the actual game play rooms as well. This could be implemented in a single object that is used in all rooms of the game.
Handling Every Control on a Game Controller
Figure 1 - Fire Game Controller
Figure 2 - Fire Game Controller with Voice
Analog Thumb Sticks
The left and right thumb sticks each provide a vertical and horizontal axis and can be pushed (or “clicked”) to act as a button.
The analog axis are read using the GML functions gamepad_axis_value. When using the analog sticks, it is important to first configure the deadzone for the stick. This is the value below which the movement is ignored. The deadzone is used to smooth movement and compensate for normal variation in electronic components. If you set the deadzone too low, the result can be jittery and erratic player movement. Setting it too high results in the game feeling sluggish and unresponsive. As you implement and test the game, you will need to find the correct balance for your players. The deadzone is set using the GML function gamepad_set_axis_deadzone. In the example code above, this is used to set the deadzone to 0.5 when a gamepad is discovered. This means the stick will need to be moved about half way for it to start registering movement in the game. The value returned by gamepad_axis_value ranges from -1 to 1.
You could use the left stick to rotate your player space ship left or right using code like this:
var h_move = gamepad_axis_value(global.gamepad, gp_axislh);
if (h_move != 0) // it will be zero until it exceeds the deadzone
if(h_move < 0)
// rotate left
else if(h_move > 0)
// rotate right
The triggers on the Amazon game controllers can be handled either as simple digital triggers or as analog triggers. To treat them as digital triggers, use the GML functions gamepad_button_check, gamepad_button_check_pressed and gamepad_button_check_released. To use a trigger as a digital button, you should first set the trigger threshold, using gamepad_set_button_threshold. This is included in the gamepad discovery code example above and establishes the degree to which an analog button must be pressed by the player to be considered “on”. The controller discovery code above sets the threshold to 0.1, which means the button must be pressed about a tenth of the way to be considered pressed.
// fire the weapon with the right trigger
Read the value using gamepad_button_value. Like the analog stick axis, this will be a value between 0 and 1.
// read the analog value from the left trigger for the throttle
throttle = gamepad_button_value(global.gamepad,gp_shoulderlb);
Face, Dpad, Stick and Shoulder Buttons
Use the GML functions gamepad_button_check, gamepad_button_check_pressed and gamepad_button_check_released to detect actions on a specified button of a specified controller ID.
// move up
Media and Back Buttons
The 1st generation Fire Game Controller includes buttons for Rewind, Play/Pause and Fast-Forward. These buttons are accessible as keyboard key actions using the GML functions keyboard_check, keyboard_check_pressed and keyboard_check_released.
// Play/Pause is being pressed
// Rewind is being pressed
// Fast-forward is being pressed
Home, Voice/Search and GameCircle Buttons
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 1st generation Fire Game Controller includes a GameCircle button. This button is not accessible to application code.
The 2nd generation Fire Game Controller includes a Voice/Search button and microphone. These are not accessible to application code.
Stay tuned for next week’s installment where I take a close look at using the Fire TV Remote and controller selection.
Miss the first two parts of the Building Retroids with GameMaker blog series?
Part 1: Studio
Part 2: Basic Controller Detection