I want to detect with what canvas object block
. We have block, circle and triangle
canvas objects.
I know there is if block in canvas.find_overlapping(x1,y1,x2,y2):
method but doesn't shows with what object is block
overlapping. It just shows if block
is touching with any other canvas object.
overlapping_object=canvas.find_overlapping(block)
, overlapping_object
could be a list that shows tags of objects that is block
touching with.
How to make overlapping_object=canvas.find_overlapping(block)
but it's correct. This one I typed here is just how could it look.
Thanks for any help!
I'm making 2D minecraft in tkinter and this is the thing that can really speed up my process.
CodePudding user response:
If you're not willing to use other libraries and only tkinter, I don't think there's a built in function in tkinter that will allow it. I am also not sure why everything must be done in tkinter as it's not at all unusual for programs to use multiple libraries. Personally, given tikinter's limitations, I would use pygame to track polygons and their intersection but would never draw them. Short of using a third library (tikinter, python default, and other), there is one other approach. I mean it's really the only appraoch.
good ole fashioned math. https://algs4.cs.princeton.edu/93intersection/ Here's some documentation on how to go about doing that. I wish you luck.