Last active
October 29, 2015 12:33
-
-
Save ekelokorpi/620bd114ca91affbd42b to your computer and use it in GitHub Desktop.
System: Accelerometer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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