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

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.