Jump to content

Using button as toggle


Maxime
 Share

Recommended Posts

Hi everyone,

 

I'm starting to use Phaser to play with html5 development.

I'm trying to make a toggle for sound, for muting.

 

Is it possible to use a button as a toggle?

I found http://www.html5gamedevs.com/topic/1730-click-sprite-and-button-question/?hl=%2Bbutton+%2Bframe#entry11867 but I wanted to know if there is a solution that is not a tricky for doing it.

 

Link to comment
Share on other sites

Yes you can, this is the code I use on an actual game :

this.soundBtn = this.add.button(50,550,'soundBtn',this.setSound,this,null,null,null);		this.soundBtn.frame = this.isSoundOn;	},	setSound : function () {		//put the sound on and change the frame	},
Link to comment
Share on other sites

I succeed to do what I wanted.

 

I did what you did Alvin but I just used the frame of my spritesheet, no need for two images.

 

That's what I did:

this.soundToggle = this.game.add.button(this.game.world.width - 150, 15, 'button', this.toggleSound, this);this.soundToggle.frame = 1;

And when cick I toggle the frame from 1 to 0 and from 0 to 1.

That's it.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...