6 Replies Latest reply on Aug 15, 2008 6:59 AM by Chunick

    sprites intersecting

    Level 7
      Is there a way to determine if two odd shaped bitmaps are intersecting? I
      have a cavelike shape and need to know when a moveable rectagle touches the
      walls of the cavelike shape. I believe I can't use "intersect" because the
      bounding rectagle of the cavelike shape does not give me the irregular
      pattern of the cavelike shape.

      I'd appreciate any help.


        • 1. Re: sprites intersecting
          multiduck
          Use: if sprite(sprite1).within(sprite2) then.... end if

          To get correct collisions on the bitmaps actual shape you need to use matte ink, read more about in director help file.
          • 2. Re: sprites intersecting
            Level 7
            M,

            Thanks. Yes, yours is the simple answer but of course doesn't handle odd
            shapes. I created a piece of code using getPixel to compare each sprite in
            one bitmap to another. It works quite well. I just created a black mask
            the same shape as each object for which I'm testing for a collision and then
            set the blend to 0 so you can't see them. It works quite well. Fast too.

            Craig

            "multiduck" <webforumsuser@macromedia.com> wrote in message
            news:g7v68c$qek$1@forums.macromedia.com...
            > Use: if sprite(sprite1).within(sprite2) then.... end if
            >
            > To get correct collisions on the bitmaps actual shape you need to use
            > matte ink, read more about in director help file.
            >


            • 3. Re: sprites intersecting
              multiduck Level 1
              Ah, didn't get that you needed to be inside the outline of the other sprite, although concave shapes without holes in them should still work with sprite within. And you could always split the cave into two sprites with a roof and a floor sprite.

              Going the mask route works too, just extract the transparency of the sprite into an image of a temporary member and check against that. I have used that in a scrolling tile based engine, copying from a generated level to a screen buffer. For complex levels this is usually more preferable than using sprites, looks smoother too, for even better scroll precision down sample from a double sized map.

              /m
              • 4. sprites intersecting
                Chunick Level 3
                Collision detection with oddly shaped sprites (ie. alpha channels) is quite possible and easy to implement. See my posts here:
                http://director-online.com/forums/read.php?2,31949,32059
                • 5. Re: sprites intersecting
                  Level 7
                  Thanks Chunick,

                  I forgot about the sprite/intersect/matte thing. That can be used with
                  sprites and Director internally does the calculations for the bounding area
                  based on the matte ink. But can it be done anticipating sprite movement?
                  Is there anyway to determine before actually setting the new loc of a sprite
                  that it WILL instersect another sprite? This would allow me, for example,
                  to place an object up against another rather than having it overlap then
                  finding that the sprites intersected. I'm sure this can be done with Havoc
                  in 3d but I'm not ready for that with the deadline I have.

                  Craig


                  I know this can be done with rects but
                  "Chunick" <webforumsuser@macromedia.com> wrote in message
                  news:g8164f$4i7$1@forums.macromedia.com...
                  > Collision with oddly shaped sprites (ie. alpha channels) is quite possible
                  > and easy to implement. See my posts here:
                  > http://director-online.com/forums/read.php?2,31949,32059


                  • 6. sprites intersecting
                    Chunick Level 3
                    quote:

                    Originally posted by: Newsgroup User
                    Is there anyway to determine before actually setting the new loc of a sprite that it WILL intersect another sprite? This would allow me, for example, to place an object up against another rather than having it overlap then finding that the sprites intersected.

                    the code is designed to test the current move before it's made and if there's a collision, then don't set the new loc - it's doing what you're describing above.