Tap actor, and drag, but not both at the same time

VoidedSkyVoidedSky Member Posts: 1,095
edited November -1 in Working with GS (Mac)
Hey all! it's been a while since I was on these forums, I don't know if anyone even remembers me, but anyway, I've still been using GameSalad. Here's my problem:
I have many actors on my screen. I want to be able to tap them, and increase an attribute. And then if I drag them, they will follow my finger. This works great on my mac. When I test it on my iPod, the tap part doesn't work. The reason is that I have code like this:

When touch is pressed, save the X and Y positions of the touch to attributes

When touch is released, check and see if the X and Y positions of the touch at the time of release equal the initial X and Y positions, If they do then increase attribute.

When touch is pressed, and the X and Y positions do NOT equal the initial positions, then constrain the X and Y positions to the touch positions.

This all works great on the computer, but when I test it, it doesn't always work, because the initial tap positions of the touch, and the release positions are different. This is because your finger moves a little bit between when you tap and release. I've tried to make it more of like a 10 pixel range, and it works a lot better, but it isn't always consistent.

Anybody have any other methods I can try?
I hope I explained this all well enough.

Thanks!

~CTM

Comments

  • osucowboy18osucowboy18 Member Posts: 1,307
    Hey CTM,

    Welcome back! Glad to see you're still using GameSalad!

    Anyway, regarding your question, here's my tip. You may already have this set up, but just going off of the way you worded it, it seems like you are missing one piece in your logic. Try this:

    Create 4 global real attributes, game.Touch X, game.Touch Y, game.Release X, and game.Release Y respectively. Next, try replacing what you have with the rule below.

    Rule:
    When actor receives event touch is pressed...
    Change Attribute: game.Touch X to game(under Devices).Mouse.Position.X
    Change Attribute: game.Touch Y to game(under Devices).Mouse.Position.Y
    End Rule.

    Rule:
    When actor receives event touch is released...
    Change Attribute: game.Release X to game(under Devices).Mouse.Position.X
    Change Attribute: game.Release Y to game(under Devices).Mouse.Position.Y
    End Rule.

    Rule:
    When Attribute game.Touch X = game.Release X AND game.Touch Y = game.Release Y...
    //execute code for just tapping the actor.
    Otherwise:
    //execute code for dragging the actor.
    End Rule.

    I haven't tested this solution in GameSalad, but it should work. Best of luck :)

    - Alex
  • VoidedSkyVoidedSky Member Posts: 1,095
    Thanks Alex,

    Just tried that...
    It doesn't work consistently.
    The release is never really the same as the initial, because of human error in tapping.....
    Anyone know a different way without using touch positions?

    Thanks!

    ~CTM
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Made a demo for you. Search for "Tap And Then Drag" in the GS creator new section.
  • VoidedSkyVoidedSky Member Posts: 1,095
    Hey scitunes!

    Thanks for the demo.
    I think I'll lower the time from 1 sec to make it be a able to drag more quickly.
    Thanks

    ~CTM
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    CowTechMan said:
    Hey scitunes!

    Thanks for the demo.
    I think I'll lower the time from 1 sec to make it be a able to drag more quickly.
    Thanks

    ~CTM

    Yeah, you can set the timer to anything longer than the typical time it take to tap. I just went with 1 to make it obvious. I would recommend that you do something to let the player know that the dragging has been activated. I went with a color change just because it is quick and easy for a demo. I would think either a change image, animation, or even particles would be a cool way to let the player know they can drag.

    cheers!
Sign In or Register to comment.