Phempt Posted November 28, 2014 Share Posted November 28, 2014 Hello guys, I want to move my sprite to left/right using the gyroscope/accelerometer.Is there something on panda to do this? Edit:Unfortunately the link here: http://www.html5gamedevs.com/topic/7064-how-to-use-accelerometer/?hl=accelerometeris offline. Quote Link to comment Share on other sites More sharing options...
enpu Posted November 29, 2014 Share Posted November 29, 2014 http://www.pandajs.net/cheatsheet/620bd114ca91affbd42b.html Phempt 1 Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 29, 2014 Author Share Posted November 29, 2014 Can I offer you a beer? Do you have a paypal account?! Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 30, 2014 Author Share Posted November 30, 2014 is there a way to detect if landscape mode is with home button to the right or left? Because the accelerometer effect on sprite, it change based on this difference. Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 30, 2014 Author Share Posted November 30, 2014 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. Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 30, 2014 Author Share Posted November 30, 2014 damn that code slowdown performance on Android (works perfectly on iOS) Quote Link to comment Share on other sites More sharing options...
Phempt Posted November 30, 2014 Author Share Posted November 30, 2014 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; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.