Skip to content

Instantly share code, notes, and snippets.

@videlais
Created August 28, 2015 23:42
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 videlais/83b4b4fb543e1f33fb07 to your computer and use it in GitHub Desktop.
Save videlais/83b4b4fb543e1f33fb07 to your computer and use it in GitHub Desktop.
Phaser Movement
var game = new Phaser.Game(
200, //The width in pixels
200, //The height in pixels
Phaser.AUTO, //The render system
"phaser", //The element
{
preload: preload, // The preload function
create: create, // The create function
update: update // The update function
}
);
// Create the variable outside of any one function scope
var sprite;
function preload() {}
function create() {
sprite = game.add.sprite(
50, // The x position
50, // The y position
'sprite' // The image cache-key
);
}
function update() {
// Check if the player is pressing Keyboard.LEFT
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
// If Keyboard.LEFT is down (being pressed),
// move 'sprite' 4 pixels to the left
sprite.x -= 4;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment