Tap actor, and drag, but not both at the same time
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
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
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
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
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
cheers!