Need a better touch radius method. Any thoughts?

0 favourites
  • 6 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • So I'm working on a little mobile game where you have to touch these randomly spawned physics balls. I have a system where there is an invisible box pinned to each ball, and I use that to detect the touch so that it has a larger radius, like so:

    <img src="http://i.imgur.com/s6wPpxO.png" border="0" />

    When the box is touched, it sets the ball as selected and destroys the box, to prevent it from being touched again. Unfortunately, sometimes when two or more balls are close to each other, you would end up touching multiple boxes, but would only select one ball. This would render the other ball un-touchable.

    I probably need to do one of two things:

    1. Instead of destroying the box, finding a way to make it un-touchable after it has been selected.
    2. Find a different method of detecting a touch within a certain radius of the ball, and getting rid of the box altogether.

    What do you guys think? I'd prefer to get rid of the box all together and find a way to detect a touch within a certain radius, but I can't seem to find anything. I may just be overlooking something extremely obvious and wasting my time, but maybe not.

    Edit: Actually the first idea on that list wouldn't work either, so I need to figure out something with the second idea.

  • I had similar issue with touch affecting multiple objects.

    Fixed it by:

    On touch myObject

    MyObject Pick top Instance

    So I only touch one at a time.

    Also you can probably get rid of the extra box - you could make a large sprite (e.g. 128x128), draw your ball in the middle, and make sure the collision bounds are set to the full sprite area.

  • I use:

    On touch start

    Pick closest object to touch.x, touch.y

    Compare value: distance(touch.x, touch.y, object.x, object.y) is less or equal than object.width+200

    • set object value 'active' to 0

    That way by using a value, no extra objects are needed and your get a perfect circular radius for the touch detection.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you both! I got it working with silkc2's method, and it works perfectly!

  • I had the same problem. The silkc2 almost worked to me. I am dealing with rectangles instead of circles, so if the player touch the rectangle corners, no event is triggered.

  • Couldnt you just make the ball sprite bigger?

    I mean, just make a larger transparent sprite, and put the ball in the middle of that. And then set to bounding box? or am i missing something?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)