Skip to content

Instantly share code, notes, and snippets.

@zackproser
Created July 13, 2015 01:16
Show Gist options
  • Save zackproser/1aa1ee41f326fc00dfb4 to your computer and use it in GitHub Desktop.
Save zackproser/1aa1ee41f326fc00dfb4 to your computer and use it in GitHub Desktop.
An example of how to create Pause and Mute buttons for your Phaser game.
/////////////////////////////
//CREATE SOUND TOGGLE BUTTON
/////////////////////////////
this.soundButton = this.game.add.button(this.game.world.centerX + 240, this.game.world.centerY - 290, 'sprites', this.toggleMute, this, 'sound-icon', 'sound-icon', 'sound-icon');
this.soundButton.fixedToCamera = true;
if (!this.game.sound.mute) {
this.soundButton.tint = 16777215;
} else {
this.soundButton.tint = 16711680;
}
//////////////////////
//CREATE PAUSE BUTTON
//////////////////////
this.pauseButton = this.game.add.sprite(this.game.world.centerX + 320, this.game.world.centerY - 280, 'sprites', 'pause-button');
this.pauseButton.inputEnabled = true;
this.pauseButton.fixedToCamera = true;
this.pauseButton.events.onInputUp.add(function() {
this.game.paused = true;
this.pauseButton.tint = 16711680;
}, this);
this.game.input.onDown.add(function() {
if (this.game.paused) this.game.paused = false;
this.pauseButton.tint = 16777215;
}, this);
...
toggleMute: function() {
if (!this.game.sound.mute) {
this.game.sound.mute = true;
this.soundButton.tint = 16711680;
} else {
this.game.sound.mute = false;
this.soundButton.tint = 16777215;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment