#๐Ÿ”’ tkinter collisoin

8 messages ยท Page 1 of 1 (latest)

cyan crystal
dense houndBOT
#

@cyan crystal

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

glad cipher
#

you just compare the x,y coordinates of the 2 rectangles you want to know if collided

cyan crystal
#

how

glad cipher
#

you just check if the x coordinate of the one rectangle with the other.. and the same with the y

#

like say this is your rectangles

rect1 = canvas.create_rectangle(50, 50, 150, 150, fill='blue')
rect2 = canvas.create_rectangle(100, 100, 200, 200, fill='red')

and you wanna see if they collide.. first you get their coordinates

coords1 = canvas.coords(rect1)
coords2 = canvas.coords(rect2)

then you check like

x1, y1, x2, y2 = coords1
a1, b1, a2, b2 = coords2

if x1 < a2 and x2 > a1 and y1 < b2 and y2 > b1:
    print'collision happened')
dense houndBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.