Maxime Posted January 28, 2014 Share Posted January 28, 2014 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 More sharing options...
Alvin Posted January 28, 2014 Share Posted January 28, 2014 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 More sharing options...
Maxime Posted January 28, 2014 Author Share Posted January 28, 2014 I imagine that this.isSoundOn is an image, isn't it?.So I need two images, one per state. Is there a way to use a spritesheet instead of having to have two images? Link to comment Share on other sites More sharing options...
Maxime Posted January 28, 2014 Author Share Posted January 28, 2014 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 More sharing options...
Recommended Posts