Making a combination music-sound on off button
Hi everyone,
I've got another head stumper, that I've been playing around with all afternoon.
I was able to make the on/off button work for both sounds and music by using separate actors. This is fine for now, but ideally I'd like to be able to turn both on/off with a single button.
I've been playing around with it for ages and cant seem to get it working.
I made both buttons work fine by using Tshirt Booths tutorial from here which was very helpful.
And also with what @JohnPapiomitis showed from this post http://forums.gamesalad.com/discussion/39171/music-and-sound-button
make a attribute called musicOff and a attribute called soundOff
In your music off button have a rule when touch is pressed:
-change attribute musicOff to (musicOff+1)%2
In your sound off button have a rule when touch is pressed:
-change attribute soundOff to (soundOff+1)%2
Then have a rule when attribute musicOff=1
-change attribute device music volume to 0
Then in the otherwise section have:
-change attribute device music volume to 1
Then have a rule when attribute soundOff=1
-change attirbute device sound volume to 0
Then in the otherwise section have:
-change attribute device sound volume to 1
When I tried to combine both change attribute's to the game.Audio.Music and game.Audio.Sound to 0 and vice versa, it fails on me.
I'm sure this has got to be a simple thing to achieve, as a lot of games have a button to turn all sounds on or off at anytime.
If anyone has done this or has input I'd appreciate it, and sure others would too in their searches.
Download UfoBlaster on the iTunes store
Best Answer
-
Socks London, UK.Posts: 12,822
Or you could use:
If touch is pressed: change attribute, Device.Audio.sound volume to 1-Device.Audio.sound volume.
Answers
thats the complicated way of doing it.
just go
:::for music:::
--RULE--
if touch is pressed:
change attribute, (Device.Audio.Music volume+1)%2
:::for sound:::
--RULE--
if touch is pressed:
change attribute, (Device.Audio.sound volume+1)%2
Thats how i do it, and it works just fine
GSINVENTION FREE TEMPLATES
@CodeMonster do they both work from the same button? or is it still 2 separate buttons?
Download UfoBlaster on the iTunes store
It can work with one button. But I prefer to have it on two seperate buttons.
GSINVENTION FREE TEMPLATES
or you can just use what @Socks said, works the same
GSINVENTION FREE TEMPLATES
Thanks to you both, I'll play around both ways and see how it works. All part of the learning process
Download UfoBlaster on the iTunes store
@CodeMonster @Socks They work beautifully. I used Socks version as my test one and it turns both sounds and music off on first touch and then back on again on second touch.
Here's the rules written completely if anyone else is looking for it.
Rule:
Actor receives event "touch" is "pressed"
Change attribute game.Audio.Sound Volume to 1-game.Audio.Sound Volume
Change attribute game.Audio.Music Volume to 1-game.Audio.Sound Volume
But for some reason on the first click I have it set to change the image to a sounds off image, but on second click it doesn't change it back to the initial image.
Here's a screen shot of how its setup. I also tried doing the otherwise, change image back to original, but then as soon as you let go of the touch it changes it, instead of on second touch.
Im thinking I may have to add another attribute in there to have it change the image back.
Download UfoBlaster on the iTunes store
Hi @aussiefaz Yes, great solutions from @CodeMonster & @Socks,
here's yet another way, a bit more programming involved but in a way, easier to see what's going on, & perhaps easier to add in changing your image back:
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
That's all working normally as it should . . .
Yes, you haven't got any rules that tell the actor to change the image to the sound on image.
Yep, same deal, there are no rules telling the actor to change the image to the sound on image on the second touch, in fact the sound on image is not mentioned anywhere in your rules, nor is a second touch mentioned anywhere, GS can't read minds !
Just stick a couple of rules in telling it to change between images at the relevant point, some like when game.audio is 1 change the image to XXX . . . that sort of thing.
Thanks again guys. I will have to nut this out.
@gyroscope, when I try that one, as soon as you release the press, the sounds come back on and the image changes back
I think Im going to have to add an attribute in that sets to either 0 or 1
Download UfoBlaster on the iTunes store
@gyroscope @Socks @CodeMonster Woohoo I did it, thanks for the leading guys, much appreciated.
So to make it work I created a self Attribute called SoundON as an integer and left it set the default of 0.0
Then my first rule was When touch is pressed. Change attribute self.SoundsOn to (self.SoundsON+1)%
Then inside that rule I created another rule with
When Attribute self.SoundsOn = 1
Change Attribute game.Audio.Sound Volume to 1-game.Audio.Sound Volume
Change Attribute game.Audio.Music Volume to 1-game.Audio.Music Volume
Change Image to my sound off image.
Then in the Otherwise
When Attribute self.SoundsOn = 0
Change Attribute game.Audio.Sound Volume to 1+game.Audio.Sound Volume
Change Attribute game.Audio.Music Volume to 1+game.Audio.Music Volume
Change Image to my sound on image.
That works a treat now. I mostly wanted this so that if someone wants to turn the sounds off at the beginning of the game they can. I should probably move the SoundsOn attribute from being a self level, to a game level for this purpose though.
Download UfoBlaster on the iTunes store
Great you got it working, @aussiefaz ! (With the other guys solutions.... )
if you're getting the sound coming back on and the image changing back on touch release, you didn't nest the second Rule in the first, and/or you used the first Rule's Otherwise section instead of the second one. Providing you change those things, it'll work seamlessly, believe me, without needing to add anything else like extra attributes set to either 0 or 1 - that's already there... I would gladly put up a little game file test to show you if you wanted, but I guess now that won't be needed now you've gone with an alternative solution.
Still, the above recommendations to get it working properly is "for the record" and to help any other member who might prefer the method I suggested.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@gyroscope I'll give that one a try tomorrow if I have time. For now its working, with what I posted earlier.
But in saying that, I want to make sure I'm doing these things the best way possible, and I'm slowly creating demos templates of each of the things I learn so I can reference them at any time
Download UfoBlaster on the iTunes store
Good on you there, @aussiefax , that's a great way to learn and build up your own template database, isn't it - that's basically what I did (and still do i.e collect gamefiles/templates, etc for reference).
So if you're still going to try out my method and you still get problems, just let me know, and i'll supply that test file for you.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
@gyroscope its definitely a great way of learning. Im understanding more and more of GS as I go with this.
Im still trying to get tables to work for tracking scores on different levels of my game, thats my next biggest problem to solve.
Right now though, Ive published a new version, but after signing the app, it only works on iPhone, the iPad versions aren't showing anything but the background, iAd, loading page and music. Not sure if its an issue with the latest GS version or not. I even just tried to make it for just iPad and still no good.
Download UfoBlaster on the iTunes store
For certain; and good to hear.
Are you meaning using Tables for saving & loading of scores? That's relatively straightforward; I seem to remember @FryingBaconStudios has a vid. tutorial on his site, if that'll help you. One thing to always consider though with using tables for saving stuff is to always make a copy of a table and use that if you want to start again at any time and have a reset table.
That's sounding most strange - not sure what's going on there without a bit more info perhaps...
Can I suggest you start a fresh thread about that? Hopefully I or another member can sort that for you.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru thanks for sharing that. I've bookmarked your youtube site to reference it again.
I have to find time again this week to get onto this part of the project
Download UfoBlaster on the iTunes store
Check out my gslogic serirs i have a video on tables there too
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru Cool thanks, I was just having a bit of a look over them before.
Im probably aiming to get to these tables for high scored levels later this week, now, Im falling behind in my normal work schedule, and with the server down today, its taken me longer than I'd expected to get the current version fully tested ready to update the app stores with it
Still need to redo this sound button from this thread to, to ensure I have the best version of it in my templates
Download UfoBlaster on the iTunes store