omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    3
    3
    917
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RocketBlaster05
      RocketBlaster05 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • ccc
        ccc last edited by

        >>> 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
        
        1 Reply Last reply Reply Quote 1
        • JonB
          JonB last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors