Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Registering When An Image is Overlapping With A Set Rectangle?
-
I'm making a minigame for my app and I just wanted to clear up some things before I begin...
I will have two rectangles, each will be on separate sides of the screen, left and right. I will have an image that spawns in at the top center of the screen and slowly falls down. I will use tilt controls in order to make the object in the center move left and right.
In order to register when the center image overlaps with a rectangle, how would I go about doing this? I would prefer if the entire image had to overlap with the rectangle before it was considered to have overlapped it.
-
>>> import ui >>> a = ui.Rect(10, 10, 100, 100) >>> b = ui.Rect(10, 10, 100, 100) >>> c = ui.Rect(11, 10, 101, 100) >>> a == b True >>> a == c False
-
I think what you want is
contains_rect
, which you would apply to the bbox of the SpriteNodes.IIRC you may be able to use
in
as well:
if other_rect in this_rect:
From the docs:
Rect.contains_point(p)
Return True if the given point lies within the bounds of the rectangle, False otherwise.Rect.contains_rect(other_rect)
Return True if the given rectangle lies entirely within the bounds of this rectangle, False otherwise.Rect.intersects(other_rect)
Return True if this rectangle intersects with the other rectangle, False otherwise.