Change Image
I have a scene that displays various information in the form of icons. When the user taps one of the icons, I intended on just changing the image to its "off/closed" version, but then I need to be able to click back on that icon to switch it back "on/open" again. Suggestions?
Best Answers
-
gyroscope I am here.Posts: 6,598
Hi @ingeniousappications
Use a boolean "toggle"; there's a more elegant way with this toggle aspect than what I'm going to show you, but this way is easier for you to understand what's going on.
Make a boolean with the value set to false. Call it Toggle.
In your icon's Rules, put:
When scene.Toggle is false
Change Image to off image
Change attribute scene.Toggle to true
otherwise
Change Image to on image
Change attribute scene.Toggle to false""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
Make sure you put the last two rules in the Otherwise section of the main rule, and you should be good to go. :-)""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
No, there's not much can go wrong with a straightforward Change attribute of a boolean...I doubt it's that.
I've just thought, perhaps the rules need to be amended if you are starting with the icon set to "off" - the rules I suggested are if your icon starts "on". (My fault, I should have guessed it'd start "off"!)
Here are the amended rules with the consideration that the start icon image is the "off" one:
When scene.Toggle is false
Change Image to on image
Change attribute scene.Toggle to true
otherwise
Change Image to off image
Change attribute scene.Toggle to false
That, hopefully should sort it now for you; fingers crossed!""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
You can do this with a table if you like! No need to though, it really is straightforward and I'm not sure where you're going wrong - it still sounds like your not using the otherwise section - or using the wrong otherwise section...; give me five minutes and I'll knock up a little game file for you so you can see...""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
I see the problem and where I've mislead you now...I assumed you knew to put it in a touch Rule....
It should be:
Rule: When touch is pressed
then this next rule INSIDE the top one:
When scene.Toggle is false
Change Image to on image
Change attribute scene.Toggle to true
otherwise
Change Image to off image
Change attribute scene.Toggle to false
I never thought something so straightforward would cause so many problems....
I'll be uploading a game file with it working very soon.
------------
https://dl.dropbox.com/u/14060718/ICON ON OFF DG.gameproj.zip
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
OK, then I don't know where it went wrong for you...
Possibly you didn't put the second rule into the first Rule...""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
gyroscope I am here.Posts: 6,598
Whatever rocks your boat! Yup, there are many probs each with multiple solutions; use whichever you feel happy with.""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
-
MarkOnTheIron Posts: 1,447
@ingeniousapplications I made you a quick demo:
https://dl.dropbox.com/u/8244920/OnOff_Button.zip
The "Easy Method" actor has the rules that @gyroscope suggested and the "Elegant Method" actor has the rules that I like to use in on/off buttons and that was hinted by @gyroscope in his first post.
Edit: Oh, I didn't notice that @gyroscope had already posted an "Easy Method" project
Answers
I used the "Change Attribute" behavior, selected the boolean attribute created before-hand, and I typed "false" into the "To:" section. I wasn't given a list of choices as I did when setting up the rule at the top.
I set the initial (open) icon to be destroyed when clicked and to spawn its (closed) version in its place. When the user clicks on the (closed) icon, that icon is destroyed, and the (open) icon is then spawned. Rinse and repeat. Crude method, but it works.