Sign in to follow this  
Phempt

How to access accelerometer/gyroscope data from PandaJS?

Recommended Posts

at the moment I used jQuery:

$(document).ready(function(){    $(window).on("orientationchange",function(){                if(window.orientation == -90){                 orientationValue = 1;                }else if(window.orientation == 90){                 orientationValue = 0;                }    });});

but if there's a pandaJS function I'll change my code.

Share this post


Link to post
Share on other sites

Oh my god, I really hate android, this code will works:

 

HEAD:

var ua = navigator.userAgent.toLowerCase();    isAndroid = ua.indexOf("android") > -1;    $(document).ready(function(){        //alert(window.orientation);        if(window.orientation == -90){                 orientationValue = 1;                }else if(window.orientation == 90){                 orientationValue = 0;        }        $(window).on("orientationchange",function(){                if(window.orientation == -90){                 orientationValue = 1;                }else if(window.orientation == 90){                 orientationValue = 0;                }        });});

player.js:

if (game.accelerometer) {            if (game.accelerometer.y < -0.2 || game.accelerometer.y > 0.2){               if(orientationValue === 1){                  if(isAndroid) {                  player.velocity.x -= game.accelerometer.y * game.system.delta * 100;                      }else{                  player.velocity.x += game.accelerometer.y * game.system.delta * 100;                  }               }else if(orientationValue === 0){                  if(isAndroid) {                  player.velocity.x += game.accelerometer.y * game.system.delta * 100;                      }else{                  player.velocity.x -= game.accelerometer.y * game.system.delta * 100;                  }               }            }else {            player.velocity.x = 0;                }        }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.