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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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