Skip to content

Instantly share code, notes, and snippets.

@corpsefilth
Created February 16, 2015 08:08
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 corpsefilth/efe7c4f2ea7236956155 to your computer and use it in GitHub Desktop.
Save corpsefilth/efe7c4f2ea7236956155 to your computer and use it in GitHub Desktop.
Phaser Sprite reference
// Create a local variable
var someSprite = game.add.sprite(250, 170, 'someSprite');
// Create a state variable
this.someSprite = game.add.sprite(250, 170, 'someSprite');
// using predefined pos
this.someSprite = game.add.sprite(game.world.centerX, game.world.centerY, 'someSprite');
// Set the anchor point to the top left of the sprite (default value)
this.someSprite.anchor.setTo(0, 0);
// Set the anchor point to the top right of the sprite
this.someSprite.anchor.setTo(1, 0);
// Set the anchor point to the bottom left of the sprite
this.someSprite.anchor.setTo(0, 1);
// Set the anchor point to the bottom right of the sprite
this.someSprite.anchor.setTo(1, 1);
// Change the position of the sprite
sprite.x = 50;
sprite.y = 50;
// Return the width and height of the sprite
sprite.width;
sprite.height;
// Change the transparency of the sprite. 0 = invisible, 1 = normal
sprite.alpha = 0.5;
// Change the angle of the sprite, in degrees
sprite.angle = 42;
// Remove the sprite from the game
sprite.kill();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment