Device orientation
If your target device supports accelerometers, you can use device orientation events
When using a device equipped with accelerometers (and a browser that supports them), you can get the device rotation data by defining an onDeviceOrientation function in your main App function.
When you test this, locking the orientation of your device may be a good idea too.
App = function()
{
this.init = function()
{
// create a red square
var sprite = new Sprite();
sprite.setSize(100, 100);
sprite.setDrawFunction(wade.drawFunctions.solidFill_('red'));
this.square = new SceneObject(sprite);
wade.addSceneObject(this.square);
};
this.onDeviceOrientation = function(eventData)
{
// calculate new position
var pos = this.square.getPosition();
pos.x += eventData.beta;
pos.y -= eventData.gamma;
// restrict new position to the screen
var w = wade.getScreenWidth() / 2 - 50;
var h = wade.getScreenHeight() / 2 - 50;
pos.x = Math.min(Math.max(pos.x, -w), w);
pos.y = Math.min(Math.max(pos.y, -h), h);
// update the position of the square
this.square.setPosition(pos.x, pos.y);
};
};
Your code was executed successfully!