0

Ive looked everywhere i could for what i am guessing has a simple solution. But i am a new programmer and am having a bit of trouble. I have a few draggable image view circles in my view and i want to prevent any overlapping between the image views. Im not looking for any serious collision solutions(friction, vectors, etc...), just something to stop the image views from going any further once they make contact with each other.

Any guidance to the solution is appreciated. Thanks.

pDev1
  • 5
  • 3

1 Answers1

0

That should just be a simple comparison of location and radii... When a drag is attempted, compute the distance between any two circles' center points (using the new location), and if that's less than the sum of the radii, they overlap. Pseudocode:

onMoveAttempted() { distance = sqrt (((moving(x) - existingcircle(x))^2) + ((moving(y) - existingcircle(y))^2))

if (distance < (radius of moving circle + radius of existing circle) then prohibit the move, as the circles would overlap end if }

user1676075
  • 3,056
  • 1
  • 19
  • 26
  • You'll need to provide more context about your particular situation. In your onDrag (presuming that's what it is, or onMove) callback, you should have access to the old location and new location. Then you should have a return value that allows you to cancel the move event (code example of what you have so far would help to be more specific). If you don't have that option, then programmatically set the location back to the old (pre-move/drag) values, or to the limit where it makes contact. – user1676075 May 07 '13 at 14:15