On/Off Button - Tutorial Question
In TSB's video, he uses a game.music integer attribute.
Then, he has a rule that when touch is pressed on the "On/Off button actor";
Change attribute game.music to (game.music+1)%2
When game.music = 0 .......
My question is;
Is it necessary to have the game.music attribute and structure the On/Off button like that? I have an On/Off button in my game for music and sound but I just made a simple rule, When touch is pressed change attribute game.music to 0 otherwise change attribute game.music to 1...
What's the best way for performance?
Then, he has a rule that when touch is pressed on the "On/Off button actor";
Change attribute game.music to (game.music+1)%2
When game.music = 0 .......
My question is;
Is it necessary to have the game.music attribute and structure the On/Off button like that? I have an On/Off button in my game for music and sound but I just made a simple rule, When touch is pressed change attribute game.music to 0 otherwise change attribute game.music to 1...
What's the best way for performance?
Comments
I use the rule you described (when touch is pressed on the "On/Off button actor";Change attribute game.music to (game.music+1)%2), in many places in my games (not only for music), and it works great (it doesn't affect performance at all).
It the second way you described, you can have some problems - because it will change your attribute everytime when the button is released. So if 1 means "Play the music" and 0 means "Stop the music", your music will stop only when you have this actor pressed, and when you realese it, the music will play again.
Or is this not as good as Change attribute game.music to (game.music+1)%2)
It switches from 1 to zero and 0 to 1 too.
??
Lump Apps and My Assets
Option 1
When touch is pressed
--Change attribute game.imageselect to game.imageselect+1
When Attribute game.imageselect > 4
--Change attribute game.imageselect to 0
Or…
Option 2
When touch is pressed
--Change attribute game.imageselect to (game.imageselect+1)%5
Add your done.
Obviously Option 2 is one less rule which means less memory used by the Game Engine. I know it may not be much but small performance improvements like this can through your game can really benefit things. Not to mention its one less rule for you to create.
Dr the rule you listed you are using instead of TSB's tutorial looks like it will switch the music to off when pressed but it also switches back on as soon as you release because the behaviors you place in the otherwise will instantly run as soon as the rules conditions become invalid.
Hope that helps you guys
Aaron
___________________________________________________________________________________
TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!
AppSolute Entertainment on Facebook
AppSolute Entertainment on iTunes