help with on/off button.
johnydee
Member, PRO Posts: 196
How would i get a on/off button when pressed it changes the image of another actor? So basically when i press the on/off button i want another actor to change its image,than when the on/off is pressed again i want the actor to change back to its first image.
Comments
create a rule and find the actor (within its layer in the expression editor) you want to change using the expression editor.
Hope this helps.
First make a game attribute - call it "button on/off" (or something suitable).
For the button:
Rule: touch is pressed:
Change attribute: game.button on/off to 1-button on/off.
For the 'actor':
Rule: when attribute game.button on/off = 1 then change image: Set image to 'A' (your first image)
Otherwise change image: Set image to 'B' (your second image)
Did it work? I can make a quick project demo and share it with you if it did not work.
Just let me know.
Ok, I will make a demo file, and share it with you later today.
Darren.
Here is the demo I made: https://www.dropbox.com/s/lk5al3f7tevg541/ON:OFF GameSalad Demo.gameproj.zip
Analyze the code and figure out how I did it (trust me, it's pretty straightforward), then use that in your own game.
Hope this helps.
The method I posted above is far simpler, just one simple rule for the actor and one simple rule for the button.
http://www.mediafire.com/?y6ph5uu3hqn6ad9
Yes, you are correct; yours is simpler.
I used expression editor, and self boolean attributes. I told him to analyze it, so he could see what I did.
I was aware that it could be done simpler, but I thought if I showed it to him this way, then he would learn how to use self attributes, and how to access another actor's attributes through expression editor, and how to use rotation as an attribute that can be used in a rule, which would ultimately help in his use of GameSalad.
Hope you understand my intentions.
EDIT: @Socks
Didn't mean to come out sounding harsh. Just wanted to let you know that.
My demo is the same as Socks' demo (except that my button changes pictures from on to off) If you are just looking for a quick solution, then download Socks' demo, as it is a very simple 1-rule demo.
But if you want to learn a few tricks that can help you in making your games with GameSalad, then download mine and look at the rules; trust me, it's very easy to understand.
And DeepBlueApps.com's post is a neat trick to learn, too.
Also Socks' demo uses an alternative way to do it, so download his too to learn that too.
Hope this helps, and hope your game goes well.
There must be another condition (rule) you're using that is causing a problem.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User