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.
sum of sprites within spriteI 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
?iRect=sprite(vSpriteNum).rect
?gTotal=0
?sendAllSprites(#AreYouWithin,iRect)
end
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
?gTotal=gTotal+1
?end if
end
Now, all you need to do is use the command:
getNumWithin(spriteNameOrNum)
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:
getNumWithin(10)
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.
sum of sprites within spriteMike - sorry for being an idiot.?I get the following script error message -
four parameters expected
iRect=sprite(vSpriteNum).rect
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.
Thanks.
No comments:
Post a Comment