2 Replies Latest reply on Oct 3, 2009 10:59 AM by schnurrenberger

    sum of sprites within sprite


      Beginner here.  Trying to write a handler to sum the number of sprites from one cast member located within the boundary of another sprite.  Thanks.

        • 1. Re: sum of sprites within sprite
          Mike Blaustein Level 4

          I would do it with some sort of callout system.  There would be a global variable, let's call it gTotal, that stores the actual count of the sprites within the other one.  Make a #movie script like this:


          global gTotal


          on getNumWithin vSpriteNum


          Then, put the following behaviour onto the sprites that are moveable (i.e. the ones that might be within the bounds of the other sprite)


          global gTotal


          on AreYouWithin me,vRect
            if sprite(me.spriteNum).rect.union(vRect)=vRect then
            end if


          Now, all you need to do is use the command:




          and check the value of gTotal.  So basically, if you are checking to see how many sprites are within the bounds of the sprite in channel 10, you would call:



          put gTotal


          and gTotal would have the correct number of sprites.  If you name your sprites (Director 10 and above), you can use the sprite name instead of the sprite number.

          • 2. Re: sum of sprites within sprite
            schnurrenberger Level 1

            Mike - sorry for being an idiot.  I get the following script error message -


            four parameters expected




            Maybe a little more explanation would help:


            I have a bitmap circle called "nucleus"


            I have bitmap small circles called "protons" that I put into "nucleus" and want a count of.


            I'm sure I'm messing up somewhere but have been at it for a while and don't see where I'm going wrong.