Skip to content

Instantly share code, notes, and snippets.

@netcell
Last active August 29, 2015 14:18
Show Gist options
  • Save netcell/a23da0dc45c04a02d177 to your computer and use it in GitHub Desktop.
Save netcell/a23da0dc45c04a02d177 to your computer and use it in GitHub Desktop.
class Joystick extends Phaser.Sprite {
constructor(x, y) {
super(game, 0, 0, 'background');
this.anchor.setTo(0.5, 0.5);
/* Pin indicator - what players think they drag */
this.pin = game.add.sprite(0, 0, pin);
this.pin.anchor.setTo(0.5, 0.5);
this.addChild(this.pin);
/* Invisible sprite that players actually drag */
var dragger = this.dragger = game.add.sprite(0, 0, null);
dragger.anchor.setTo(0.5, 0.5);
dragger.width = dragger.height = this.width;
dragger.inputEnabled = true;
dragger.input.enableDrag(true);
this.addChild(dragger);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment