Change Image

ingenious.applicationsingenious.applications Member Posts: 102
edited June 2012 in Working with GS (Mac)
Hey guys,
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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited June 2012 Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited June 2012 Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited June 2012 Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited June 2012 Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited June 2012 Accepted Answer

    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

  • gyroscopegyroscope I am here.Posts: 6,598
    edited July 2012 Accepted Answer

    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

  • MarkOnTheIronMarkOnTheIron Posts: 1,447
    edited July 2012 Accepted Answer
    @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

  • ingenious.applicationsingenious.applications Member Posts: 102
    Thanks gyroscope. Unfortunately, even with following you instructions, I get the same result I was getting before, which is the image only changes for half a second and then changes back to the original image.
  • ingenious.applicationsingenious.applications Member Posts: 102
    I've followed your instructions to the "T." The only thing I can think of is the very last line where I'm changing the attribute of the boolean back to false could be messed up.

    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.
  • ingenious.applicationsingenious.applications Member Posts: 102
    Hmm...that didn't do it either. Just like last time, once I click on the icon, it changes (to "off") for just a second, but then changes back (to "on"). I wondering if I'll have to do this with a table. I greatly appreciate you giving some of your time to try to help me out, though.
  • ingenious.applicationsingenious.applications Member Posts: 102
    No, I'm quite new to this, but I knew enough that the touch rule had to be used.
  • ingenious.applicationsingenious.applications Member Posts: 102
    Coming back to this problem earlier this morning, I figured out another method to solve this problem.

    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.
Sign In or Register to comment.