It is now possible to play the Chrome dino game using a gamepad. How many of you have played the Dinosaur game, also known as the T-Rex game, in the Chrome web browser? In case you unaware, the Dino game remains the most popular easter egg in Google Chrome for years.
The in-built browser game appears every time you are disconnected from the Internet and works offline. Besides, you can manually navigate to chrome://dino and play the game anytime you want, even if you are connected to the Internet.
Play the Chrome dino game using a gamepad
“Another fact that arguably is more useful to know and that you might not be aware of is that in arcade mode you can play the game with a gamepad. Gamepad support was added roughly one year ago as of the time of this writing in a commit by Reilly Grant. As you can see, the game, just like the rest of the Chromium project, is fully open source,” said Thomas Steiner, Web Developer Advocate at Google.
How to play the Chrome dino game using a gamepad
The Gamepad API supports Chrome across desktop and mobile. In case you want to verify if the Gamepad API is supported, you can use the following code:
if ('getGamepads' in navigator) { // The API is supported! }
The Chrome dino game with gamepad support represents several fields, as follows:
- Id refers to the brand or style of a connected gamepad device.
- Index refers to the index of the gamepad in the navigator.
- connected indicates whether the gamepad is connected to the system.
- timestamp is the last time the data for the particular gamepad device was updated.
- mapping refers to the button and axes mapping in use for this device. Currently, the only mapping is “standard”.
- axes is an array of values for all axes of the gamepad, linearly normalized to the range of -1.0–1.0.
- buttons indicate an array of button states for all buttons of the gamepad.
Since buttons can be both digital and analog, there are various properties defined to check if the gamepad supports digital or analog controls.
For more information, check out this detailed Web.Dev blog post.