Choeeey Posted December 28, 2014 Share Posted December 28, 2014 I am trying to make a tilt based game and hence trying to use the gyro tracking function. I cannot understand why this code will not work? I apologise for the indentation, it did not copy well in here. Any help would be very appreciated as it is stressing me out var gyroa = 0, gyrob = 0, gyrog = 0; myGame.Test2 = function(game1) { game = game1; }; myGame.Test2.prototype = { create: function() { gyro.startTracking(function(o) { gyro.getFeatures(); gyroa = o.alpha; gyrob = o.beta; gyrog = o.gamma; }); game.stage.backgroundColor = '#90EE90'; this.ball = this.add.sprite(230,200, 'ball'); this.ball.anchor.setTo(0.5,0.5); game.physics.arcade.enable(this.ball); this.ball.body.bounce.setTo(0.3, 0.3);this.ball.body.linearDamping = 1;this.ball.body.collideWorldBounds = true; }, update:function(){ var collision = game.physics.arcade.collide(this.ball, this.walls); this.handleOrientation(gyrog, gyrob); }, handleOrientation: function(xgyrog, ygyrob) { xgyrog = gyrog; ygyrob = gyrob; var x = xgyrog; // range [-90,90] var y = ygyrob; // range [-180,180] this.ball.body.velocity.x += x/4; this.ball.body.velocity.y += y*5; }, }; Link to comment Share on other sites More sharing options...
rich Posted December 29, 2014 Share Posted December 29, 2014 Does it work if you remove physics from the equation? I.e. just dump out the x and y values from the callback, are they populated with anything? If so, what sort of values do they contain? I would suspect they'd be tiny, maybe even zero based, but have never used a gyro so no idea. Link to comment Share on other sites More sharing options...
Recommended Posts