Python Forum
Make rectangle snap to other rectangle corners
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make rectangle snap to other rectangle corners
#2
(Aug-13-2021, 09:22 AM)Pedroski55 Wrote: Maybe create a bigger, unseen version of r0 and if it collides with a corner of r1, set that point as r0.x, r0.y ???
Yes this is exactly what to do. There is a built in method for these kind of operations for Rects called inflate() and inflate_ip() (inflate in place .ie modify the original instead of creating a new rect)

I would use pygame rects for objects in classes. An original rect for its coordinates. Another inflated rect for its collision detection. You dont need to create a separate object for rect collision.

This is not a drag and drop feature, but a drag example. I think it would illustrate why use classes and will make your world a lot easier if you. It would better organize your code and make it easier for you and us to understand.
https://github.com/Mekire/pygame-samples...ag_text.py

Your code is similar to the non class code. So maybe looking at the comparisons would help in how to use classes.
https://python-forum.io/thread-34609.html

Ugggg. I wrote a longer explanation but it gave a 400 request when i edited the post so i lost it all and now have to leave. sorry.
Recommended Tutorials:
Reply


Messages In This Thread
RE: Make rectangle snap to other rectangle corners - by metulburr - Aug-13-2021, 10:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] Surface and rectangle in pygame Fabrizio_fg 6 2,508 May-27-2023, 09:15 AM
Last Post: Fabrizio_fg
  Rotating a rectangle CompleteNewb 19 13,810 Aug-28-2021, 03:23 PM
Last Post: CompleteNewb
  [PyGame] Rectangle keeps teleporting? keyfive 1 3,255 Jun-27-2018, 11:49 PM
Last Post: sonnekrieger7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020