Skip to content

Instantly share code, notes, and snippets.

@aaronhampton
Created October 30, 2014 01:15
Show Gist options
  • Save aaronhampton/bfa4f52bdf786697d011 to your computer and use it in GitHub Desktop.
Save aaronhampton/bfa4f52bdf786697d011 to your computer and use it in GitHub Desktop.
Enable physics on a Phaser Graphics Circle
// First, add your sprite and enable physics on it
sprite = game.add.sprite(game.world.centerX, game.world.centerY);
game.physics.p2.enable(this.sprite);
// Create a shape
var circObj = new Phaser.Circle(0, 0, 25);
// Set the body size of your sprite
sprite.body.setCircle(circObj._radius, 0, 0);
// Draw the graphics
var ring = game.add.graphics();
ring.lineStyle(2, 0x000000, 0.25);
ring.drawShape(circObj);
// Add the graphics as a child to your sprite
sprite.addChild(ring);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment