How to Touch-to-Drag when actors overlap? Tricky!

jkornoffjkornoff Member Posts: 55
edited November -1 in Working with GS (Mac)
Sorry for the long post, but this problem may help others out.

I'm going back in to Detonate! and making small fixes and tweaks. One thing I wanted to fix with 1.0 is what I perceived as a bug when if you spawned multiple bombs at one time (and they spawn on top of each other) and you try to drag one off the 'top of the pile', there would only be that one visible. The other wouldn't be seen below it. They disappeared.

So I thought I would be smart and slightly randomize the spawning location of the bombs so that they don't appear right on top of each other. Problem solved! Nope.

Clicking or touching one makes the others disappear too. Then I realized that maybe they WEREN'T really gone at all, but instead they were all being moved together, one on top of each other as a group! My touch-to-drag behavior is selecting all the actors under the touch, lining them all of them up on top of each other (because constrain self.position to game.mouse position).

This is what is happening, I've confirmed it. I have no idea how to fix it!

I could create some sort of rule that doesn't allow actors to overlap. That's pretty hard!

I wish there was a way to limit the click to drag to only the actor on 'top' so that if you had a stack, you could just drag that one off and reveal the others below it instead of selecting all the actors in the stack. It's like the 'touch' is penetrating through all the layers in the scene.

One thing I wanted to do in v1.1 was to increase the touch area of the bombs so that they were easier to move with your finger on the iPhone. Well, obviously this would mean there is more of an area for multiple bombs to overlap then and this problem gets worse.

Any ideas?

You can see what I'm talking about by going into Detonate! lite and creating three red bombs in a row on Level 2. http://gamesalad.com/game/play/36739

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    yes, I cannot think of a solution to that either. Right now, everything under your cursor gets the Touch event...

    It would be nice to have a way to trap all touches in the highest actor in the layer(s)...

    I have tried as many things as I can think of, but I don't see a way around this issue currently.
  • jkornoffjkornoff Member Posts: 55
    Is there something I can do with the constrain self.position to game.mouse position attribute? I'm thinking if there is a way to keep an actors relative position the same distance away from a touch. So if two actors were side by side, at keep them in that same relative position while they are dragged instead of each jumping to the exact same game.mouse position.
  • ORBZORBZ Member Posts: 1,304
    I have experimented with this a little bit too. I forget exactly what my results were because it was awhile ago and I gave up. But I think that I came pretty close by setting a global flag "dragging" to true INSIDE a timer set to every random(0.01, numActors / 100) and the first actor to receive the event would set it and the others would miss it. The timer makes parallel operations linear and each new actor is just a little bit slower than it's previous.

    It wasn't perfect and you couldn't guarantee which actor would receive the event. It was a hack and it was on 0.7.0 that I got it sort of working... I haven't tried it in 0.8.2
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @jkornoff: you can set a 'touchOffset' when you touch the actor(s) like this:

    Create a real attribute in the actor called something like 'touchOffset'

    Create a Rule like this in the Actor:

    Rule
    When Touch is Presses
    Change attribute self.touchOffset to: game.Devices.touch1.X - self.Position.X
    Constrain Attribute self.Position to: Touch1.X+self.touchOffset

    That should do the trick. Not sure about multitouch, but this should get you going in the right direction
  • jkornoffjkornoff Member Posts: 55
    Thanks Firemaple. I'm just gonna have to dig in there and work it out. Good direction though.

    @orbz - "The timer makes parallel operations linear and each new actor is just a little bit slower than it's previous."

    Can you expand on that a little bit? The next problem I face is that simultaneous actions (detonations) controlled by timers work great on GS web, but don't work well at all on the iPhone. If I trigger two of the same-type bombs at the same time on the iPhone, nothing happens. The two cancel each other out it seems. Two different types at the same time or two of the same type but set different timers work fine on the Phone.

    Any and all combos work fine on the web, so its hard test. Your comment may provide some insight.
Sign In or Register to comment.