views:

123

answers:

1

Hi guys, Say I have objects within the canvas with a tags 'stopped' and 'flying'. How do I check if any of this objects overlap each other?

Thanks!

+1  A: 

You can use the method find_overlapping

find_overlapping(x1, y1, x2, y2) => tuple

Returns a tuple of all items that overlap the given rectangle, or that are 

completely enclosed by it.

And then loop through the result list looking for your tag.

Carlos Tasada
Right! And then if tuple > 0, then something is overlapping!Pardon my incompetence, how do I insert x1, y1, x2, y2 coordinates from each of the tagged objects?
you can loop through your objects or tags and do a bbox. This will give you back the coordinates
Carlos Tasada
works, thanks! falling = canvas.find_withtag('falling') stopped = canvas.find_withtag('stopped') for f in falling: for s in stopped: if (canvas.bbox(f)[3] == canvas.bbox(s)[1])and(canvas.bbox(f)[0] == canvas.bbox(s)[0]): canvas.itemconfigure( 'falling' ,tag='stopped')
Please, mark the answer as accepted if it helped you ;)
Carlos Tasada