5 Replies Latest reply on Jul 27, 2006 9:35 AM by TzK2

    Intersecting registration points?


      I'm making a game where you drag a blob around the screen and click 'select' when it's where you think the correct area is. I want to have 2 possible outcomes - a) the blob intersects the very centre of the correct area (i.e. the reg. point of the invisible 'target' sprite) and b) the blob intersects some other part of the target area. Can I use the intersect command with reg. points, or do I have to create another very small target sprite and position it in the middle of the larger target area? Are there other better ways of doing this? Any help with syntax would be appreciated.

      Also, if a button shape is irregular (i.e. it doesn't fill the bounding box), is there an easy way to have only the shape itself react to clicks etc., and not the transparent section of the sprite?

      Many thanks,

        • 1. Re: Intersecting registration points?
          James Newton, ACP Level 3
          You can use aPoint.inside(aRect) to determine if the center of the correct area is inside the blob.

          You can use matte ink (36) to check for clicks only on the opaque part of a sprite. This will not work on images that have "holes" in them. To do this, you can check the value of the alpha channel in a 32-bit bitmap. See http://nonlinear.openspark.com/tips/imaging/irregular/
          • 2. Re: Intersecting registration points?
            TzK2 Level 1

            Many thanks for the reply. I've tried using this but can't quite get it working - could you have a look at my code and tell me where I'm going wrong? It is supposed to be a button behaviour, clicked when the locator 'blob' has been positioned by the user. If the blob touches the middle of the target it should say "Bang on!!" (but this doesn't happen). If it's off-centre but within the larger taget area, it should say "Nearly", and if off target completely, it should say "Too far away".

            on mouseDown me
            blob = the rect of sprite 14
            target = sprite(8).loc
            if inside(target, blob) then
            member("Main dialogue").text = "Bang on!!"
            set targetRect to the rect of sprite 8
            set blobRect to the rect of sprite 14
            set overlap to intersect(blobRect, targetRect)
            set overlapValue to the right of overlap
            if overlap = 0 then
            member("Main dialogue").text = "Sorry, too far away."
            member("Main dialogue").text = "Nearly, half marks."
            end if
            end if
            • 3. Re: Intersecting registration points?
              James Newton, ACP Level 3
              It looks like you are:

              a) checking if the target loc is inside the blob rect (rather than the other way around)
              b) confusing 'overlap' and 'overlapValue'

              Here's my version. Note that I have also changed mouseDown to mouseUp, and tidied up the flow of the handler.

              on mouseUp(me) -------------------------------------------------------
              -- ACTION: Tests the relative positions of sprites 8 and 14 and
              -- shows an appropriate text

              -- HARD-CODED sprite and member references
              vTarget = sprite(8)
              vBlob = sprite(14)
              vDialog = member("Main dialogue")

              -- Check if loc of blob is inside target rect
              vTargetRect = vTarget.rect
              vBlobLoc = vBlob.loc

              if vBlobLoc.inside(vTargetRect) then
              vText = "Bang on!!"

              -- Check if blob rect intersects target rect
              vBlobRect = vBlob.rect
              vOverlap = vBlobRect.intersect(vTargetRect)

              vIsOverlap = max(vOverlap) -- 0 if no overlap

              if vIsOverlap then
              vText = "Nearly, half marks."

              vText = "Sorry, too far away."
              end if
              end if

              vDialog.text = vText
              • 4. Re: Intersecting registration points?
                TzK2 Level 1
                Thanks, that's helped a lot (I'm a beginner as you can probably tell, so it's really useful for me to see how my code should look!) I'm nearly there - I did actually want it to check if the target loc was in the blob rect, as the two conditions are 1) blob intersects with centre of target (full marks), 2) blob intersects some other part of the target (half marks), and 3) no intersection with target (no marks). I've worked this out based on your code, but I need it to relate to the cast member's actual shape, not the bounding box surrounding it. The target cast member is a rectangle, so it's fine when it lies flat, but it often needs to be in a rotated position, and when this happens the bounding box registers as a 'hit' rather than just the shape itself. Is there a way around this?

                Thanks so much for your time.
                • 5. Re: Intersecting registration points?
                  TzK2 Level 1
                  Can anyone help me solve the above problem? (see previous message)