3 Replies Latest reply on May 14, 2007 7:25 PM by Doc Raman

    In need of help for a command

    Xpuc
      Hello again evryone,

      So far you guys have been of great help. Now I have another question. It is related to the command sprite(spriteNumber).intersects spriteNumber. In my last post I asked how to make a ball bounce realisticly, however this idea is now replaced by the platform at the bottom of the screen shooting the boxes above (Space Invaders sort of). For those who are not familiar with my previous post the game is: square shapes falling down from the top of the screen and the player has to shoot them all to advance with his ship at the bottom of the screen (ship is controlled left/right by the mouse, shoot - LMB). To detect if the bullet sprite has hit a box I use the command sprite(BulletBeingHere).intersects(BoxBeindHere). But with this command I do not get consistent results - it detects that the two sprites intersect whenever it feels like it. I cannot recorgnise a pattern, it is absolutely random (from my point of view). I will attach the piece of code I am using. Please if you can guide me into fixing this. I suspect I am doing something wrong with the sprites' properties, the sprites are bitmaps firs one is box, second one is oval-shaped object, both with Ink:Matte (from Property Inspector), so to 'merge' with background. In the code: custom handler detectHit, spNum is the number of the box sprite, 11 and 12 are two bullets sprites, sprite(spNum).locV = -600 kicks out of the stage the box which has been hit by the bullet, sprite(11 or 12 here).locV = 0 resets the bullets in their original position.

      P.S. I get this weird problem with Director not being able to publish/compile properly the project, everything is working just fine whilst in Director, and after publishing to exe file, either a critical error, or background is not displayed, or some sprite is not displayed. But I don't think that is related to the above problem.

      Thanks
        • 1. Re: In need of help for a command
          Doc Raman Level 1
          Looks like you are not using the intersect function correctly (note: it does not end with an "s"). It doesn't return a boolean. It returns a rectangle of the overlap region. If they don't overlap it will give you a value of rect(0, 0, 0, 0)

          newRect = aRect.intersect(bRect)

          • 2. Re: In need of help for a command
            Level 7
            > Looks like you are not using the intersect function correctly (note: it does
            > not end with an "s"). It doesn't return a boolean. It returns a rectangle of
            > the overlap region. If they don't overlap it will give you a value of rect(0,
            > 0, 0, 0)

            There's nothing wrong with 'intersects()' - from the docs:
            sprite...intersects
            Usage
            -- Lingo syntax
            sprite(sprite1).intersects(sprite2)
            sprite sprite1 intersects sprite2
            Description
            Keyword; operator that compares the position of two sprites to determine
            whether the quad of sprite1 touches (TRUE) or does not touch (FALSE) the
            quad of sprite2.

            If both sprites have matte ink, their actual outlines, not the quads,
            are used. A sprite’s outline is defined by the nonwhite pixels that make
            up its border.

            This is a comparison operator with a precedence level of 5.
            • 3. Re: In need of help for a command
              Doc Raman Level 1
              intersect(s)....I think I forget more Lingo every day...time to pull out a good old book and browse a bit on a rainy day :)