Jump to content

Change angle of sprite based on accelerometer


KevinnFtw
 Share

Recommended Posts

Hi,

 

It's my first time using the Phaser.io and I must say it is great so far.

I've ran into a problem, I want to create a webbased game that you can play on a mobile device using the accelerometer.

 

What I want to do is change the angle of a sprite based on the x and y value of the accelerometer.

Problem is, I don't know how to do this at all. 

 

I'm using the gyro.js library to get the tracking values. At the moment I'm using this code in my create() function to move the sprite on the screen (but it doesn't rotate accordingly):

if(gyro.getFeatures().length > 0) {     gyro.frequency = 10;     gyro.startTracking(function(o) {     player.body.velocity.x += o.x;     player.body.velocity.y += o.y;     });}
 
Can anyone tell me how I could accomplish this?
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...