3 Replies Latest reply on Jun 15, 2008 7:16 PM by fazstp

    One object inside another

    bmohnsen3
      How do you test to see if one object is inside of another.

      One object is a movable bitmap.
      The other object is an invisible shape.

        • 1. Re: One object inside another
          Level 7
          Check out the intersect() command in the help. It will tell you if one
          rect intersects another, and it will tell you the rect of the intersection.

          if sprite(1).rect.intersect(sprite(2).rect)>rect(0,0,0,0) then
          --there is some intersection
          end if


          if sprite(1).rect.intersect(sprite(2).rect)=sprite(1).rect then
          --sprite 1 is ENTIRELY inside of sprite 2
          end if


          if sprite(1).rect.intersect(sprite(2).rect)=sprite(2).rect then
          --sprite 2 is ENTIRELY inside of sprite 1
          end if
          • 2. Re: One object inside another
            Level 7
            You mean something like:

            myRect= sprite(1).rect.intersect( sprite(2).rect )
            if myRect.width then
            -- do stuff
            end if

            Or, if by inside you meant.. well, inside:
            if myRect.width= sprite(2).width and myRect.height=sprite(2).height then
            ....

            Assuming that sprite 2 is the smaller of the two sprites.


            "bmohnsen" <webforumsuser@macromedia.com> wrote in message
            news:g34dph$anc$1@forums.macromedia.com...
            > How do you test to see if one object is inside of another.
            >
            > One object is a movable bitmap.
            > The other object is an invisible shape.
            >
            >


            • 3. Re: One object inside another
              fazstp Level 2
              You could try sprite within or sprite intersects

              if sprite( 1 ).within( 2 ) then
              -- it's within
              else
              -- it's not
              end if