Skip to content

Instantly share code, notes, and snippets.

@ekelokorpi
Last active October 29, 2015 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekelokorpi/620bd114ca91affbd42b to your computer and use it in GitHub Desktop.
Save ekelokorpi/620bd114ca91affbd42b to your computer and use it in GitHub Desktop.
System: Accelerometer
game.module(
'game.main'
)
.body(function() {
game.addAsset('panda.png');
game.createClass('Player', {
init: function(x, y) {
this.sprite = new game.Sprite('panda.png', x, y).addTo(game.scene.stage);
this.sprite.anchor.set(0.5, 0.5);
game.scene.addObject(this);
},
update: function() {
if (game.accelerometer) {
this.sprite.position.x -= game.accelerometer.y * game.system.delta * 50;
this.sprite.position.y -= game.accelerometer.x * game.system.delta * 50;
}
}
});
game.createScene('Main', {
init: function() {
var player = new Player(game.system.width / 2, game.system.height / 2);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment