Introduction
Game controllers have always brought flexibility to the game enthusiasts to plug and play to all the compatible game consoles. In the earlier days, the game controllers are meant for a specific console. Now with the advent in technology, a single game controller is compatible to multiple consoles. In this article, we will take a look at how using the Tizen TV APIs we can take control of the game controller inputs and use it in our application. Whether you are a seasoned developer or an experienced one, we will go through the details on how you can effectively utilize the Tizen TV API to get proper control of the game controller input and use it effectively in your application.
Brief idea on game controllers
A game controller is a custom built gaming device that obtains inputs from the user and helps to navigate / play the game. Modern game controllers can connect to a variety of compatible gaming or general purpose devices. Game controllers come in various forms like gamepads, joysticks, steering wheels, motion controllers, keyboard / mouse, VR controllers , mobile device controllers etc. With the latest updates in the smart TV platform, more number of smart TV providers like Samsung, LG, Sony and other generic android based smart TVs are providing support to game controllers and access content based on the controllers. Now we will take a look at how we can control the game controller inputs using the Tizen TV API. All Tizen TV models after 2016 has support for gamepad controllers.
Gamepad Tizen TV integration
Lets take a look at how can we configure a Tizen TV application to receive inputs from the connected game controller programmatically. We can start with an empty JavaScript Tizen TV application that is created using the Tizen project creation wizard. First we need to list out the gamepad devices that we are aiming to support in our application. For that we need to add the following line to the application config file.
<tizen:metadata key='http://samsung.com/tv/metadata/gamepad' value='xxx'>
</tizen:metadata>
The value xxx holds the gamepad model. The value changes based on the number of gamepad controllers you are aiming to support in your application.
1 model: dualshock4
2 models: usbgamepad::xxx
3 models: xxx::yyy::zzz
Once you have added this line, your smart TV will show the prompt to connect the specified gamepad.
Handling game controller inputs
The gamepad API provided for the Tizen TV is based on the W3cGamepad Interface standard. It is an official W3C standard. This have various APIs to detect connect, disconnect, key press events etc from the connected gamepad controller.
The gamepadconnected event is fired when the gamepad is connected
var gamepad;
window.addEventListener('gamepadconnected', function(event) {
gamepad = event.gamepad;
console.log('event.gamepad : ' + JSON.stringify(event.gamepad));
});
The gamepaddisconnected event is fired when the gamepad is disconnected from the Tizen TV
window.addEventListener('gamepaddisconnected', function() {
gamepad = undefined;
});
To get information related to the gamepad button clicks
console.log(gamepad.axes[0]); // axes[0]
console.log(gamepad.buttons[0]); // buttons[0]
After getting the game axes and the buttons, the user can control the button clicks from the game controller and do the necessary actions in the application / game.
Concepts related to gamepad
When working with a gamepad, it will be helpful, if we could know the concepts associated to it. A standard gamepad has 4 axes and upto 17 buttons (including programmable ones). Different gamepads have different layouts and buttons based on their models. Here is an example of a simple gamepad controller.
And a complex one as well
Gamepad limitations in Tizen TV
The following gamepad limitations apply to Tizen TV
- Tizen TV does not support vibration.
- You can connect a maximum of 2 gamepads simultaneously.
- After the user connects the gamepad, interaction using the gamepad becomes available only after the user presses any button or moves any axis.
Conclusion
With the advent of modern JavaScript rendering engines, modern web based smart TVs are more capable of handling games and other applications. Now with the ability to control and process the game controller inputs, the user can integrate the game controller for a wide variety of application use case scenarios. Tizen TV API provides various methods to interact with game controllers. The game controller support is based on the type of the Tizen TV model that you are trying to connect to and it’s support for game controller inputs. We will look into other methods of interacting with the TV in future blog posts.