Sunday, January 11, 2015

Accelerator as control

I found this tutorial online (, i get the code by by right click inspected code then i copy down to modified.

For this project i only required the X accelerometer so i remove the y and z and just get the X code to use it move my space ship.

I had made the code to send a data like "z" to the server every when the accelerometer is trigger. then check whether is positive or negative. each send different data.

From here i bring in the code to my game control.  

Using the same theory like i modified above. now i use it to trigger function when accelerometer was being trigger. when positive the space ship will move right. negative then move left.

When accelerometer meter move positive then it will call the function sendtoleft1() then when sendtoleft1() was call it will send "a" to the game browser.

So when game browser received the data "a" it will call another function which is left(); which is a function send it a key press code. and the key is press the ship will get the signal and move to left.


References,. 'Accelerometer Javascript Test'.[online] Available at:  [Accessed 11 Jan. 2014]

No comments:

Post a Comment