How to limit direction when using touch offset?

gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
edited December 2011 in Working with GS (Mac)
Hi all, hope you're having a nice Christmas!

I've abandoned my logic puzzle app and have started another project, one which'll see the light of day by February/March... no really, I'm committed to this one and getting well into it.

Anyhow, small problem: I have a sliding panel; the user touches and drags it and it slides down, on release it slides back up again as I want; all good... (the Rules are based on TSB's "Touch Offset when constraining actor to the mouse" video). I want the user to be able to slide the panel down, but not up and I've been scratching my head trying to figure out how to put this in the Rules. I'm sure it's straightforward enough but I can't find the solution.

Here's the Rules, allowing the panel to slide both ways:

Rule
When touch is pressed
Change attribute self.offset y to game.Touches.Touch 1.Y - self.Position.Y
Change attribute self.drag to true
otherwise
Change attribute self.drag to false

Rule
When self.drag is true
Constrain attribute self.Position.Y to game.Touches.Touch 1.Y - self.offset y

Rule
When Any
Touch is released
touch is outside
Move To ---- slides back to closed

So to repeat, the problem is to limit it so that it can only be dragged downwards, not up at all. Any help appreciated, thanks.

----------------------------------------------
http://davidgriffinapps.co.uk/

""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Comments

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    If I get what you're saying, you could try creating a StartY attribute and set the startY to self.position.Y and then have it so that it will only constrain to touch when it is less than startY, if it is being dragged up it will go above startY and not constrain.

    Ace
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Ace, thanks for the swift reply. I tried your suggestion (and something similar before) but no joy unfortunately. It's definitely in the right ballpark tho, I'm certain you're close, thanks. Any other ideas anyone?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Take 2: it works some of the time: I added a new attribute ConstTouch. Then in the first rule added, Constrain ConstTouch to self.Position.Y. Thn after "When self.drag is true added When ConstTouch +< 169. Seems to work the first time, but try again and it jumps over the "limit" of 169 before stopping agin too high, if you see what I mean. I guess I'll experiment on.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Take 3: it's not "perfect" but I've got it working I think: when ConstTouch > 169 then Change attribute self.drag to false. It still moves a couple of pixels up but then won't go any more. THat'll do I'm thinkng. Thanks again Ace for your help in pointing me in the right direction. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    Here's a stab in the ballpark idea that's a little crazy lol - If device.mouse.positionY < self.position.y constrain attribute self.position.y to device.mouse.position.y

    Try that, see what happens lol

    Ace
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi uptimistic, thanks; I'll check out my messages now. It'll be interesting to see your solution. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Appreciated Ace, thanks but I'm thinking that'll bypass the offset...I'll check it out all the same. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    Let me fire up Gamesalad and see if I can get it working

    Ace
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Ace: Cheers for that!

    uptimistic: I can't seem to get into my profile to check out messages at the moment for some reason; would you mind emailing me your message please? contact@davidgriffinapps.co.uk

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • firemaplegamesfiremaplegames Member Posts: 3,211
    edited December 2011
    You can also try using the min() function in the expression editor.
    Essentially:
    Constrain self.y to min(initialYPosition, mouseY)

    You'll need to deal with your offset but that is the basic logic.

    Edit: oops! min(), not max()
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    I have the offset done :)

    Let me upload it

    Ace
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    http://mynameisace.com/files/GSOnlyDragDown.zip

    Firemaple's way would be more elegant if you get that up and running with the offset.

    Ace
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Joe, long time no hear! Hope all's well; looking forward to your next excellent game. :-)

    I've shied away from using max() in the past but I'll bite the bullet and experiment with your suggestion; thanks for that.

    PS Uptimistik kindly emailed me another solution (Thank you Jonathan); it's great that there's "so many ways to swing a cat" here!

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Wow, solutions are coming thick and fast now... thank you as well for your time, Ace; i'll check it out now.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    I never go with conventional programming logic, I just swing the cat like a crazy person and see what happens :)

    Ace
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    That works a treat Ace, spot-on, thank you! I like it that it's rock solid when you try to move it upwards as apposed to my solution where it still moved a few pixels.

    Thanks to all you guys for your help, much appreciated.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.