📜 ⬆️ ⬇️

Port Flappy Bird on Gear 2

Today we will learn how to port HTML + JS applications to Samsung Gear 2.

Take the game from the repository and clone it to our locale. If you run it in a browser, you will see the game itself:

Flappy bird
')
Tizen Wearable, on which the clock works, supports applications only on html + js, so with the help of simple manipulations, let's make the game start on the clock.
To get started, download Tizen SDK for Wearable for your OS. After installation, run the Tizen IDE for Wearable and create a new project (File -> New -> Tizen Wearable Web project). On the Template tab, select Basic, enter the project name below, and click Finish.

From the new project, you can delete the file index.html and directories: css, js. And then, copy to the project the files that were in the repository with the game.

In the end, it should turn out like this:

Tizen ide

To start the game, click the green Play button in Tizen IDE and you will see a fully working game on your watch.

Flappy Bird on Gear 2

To test the game without a clock, you need to run the Emulator Manager in the Connection Explorer and create a virtual machine with Tizen Weareable in it. And you can also go to RemoteTestLab . There you can test the application on a real device, physically located at Samsung.

When you try to play the game on the clock, the inhibition of the game and sounds that are lagging behind or not playing at all will immediately catch your eye. For this platform - this is normal. She simply does not have time to handle all the events as quickly as the browser on the PC does, so there are brakes. To smooth the impression of the games created, it is best not to use sounds for the character’s actions in them, but, for example, to replace them with vibration.

Vibration is very simple to use. You just need to call the code, like:

navigator.vibrate(2000);

This code will cause the clock to vibrate for 2 seconds.

navigator.vibrate([1000, 1000, 2000, 2000, 1000]);

Such a code will cause the clock to vibrate according to a pattern: 1 second of vibration, 1 second of inactivity, 2 seconds of vibration, 2 seconds of waiting.

In order for the game to fit into the concept of Tizen Wearable, you need to add the ability to close the application on the swipe from top to bottom. To do this, open the js / main.js file and add the following lines to the end of the file:

 window.addEventListener("tizenhwkey", function(ev) { if (ev.keyName === "back") { tizen.application.getCurrentApplication().exit(); } } ); 


Now you can not only play, but also close the application when you need.

Another interesting point when creating applications for Gear 2 + any Samsung device is that you can create a new type of control for Android games. When you play games with your watch, you can track the movement of your hand using the accelerometer.
For example, you can make games like golf, boxing, billiards, bowling, where physical effort is needed to get the best points for the game.

At the moment in the Samsung Store, I managed to launch a game in which the character's jump is the real jump of the user, and the run of the character is the real run of the user on the spot.

If you are interested in information about the implementation of applications under Tizen Wearable, as well as information on downloads and purchases in the Samsung Store, you can ask me to write a new article.

Examples on the use of virtually any Tizen functions can be viewed from the Tizen IDE by going to Help -> Help Contents.

Source: https://habr.com/ru/post/230733/


All Articles