PDA

View Full Version : which sprite is another sprite over?



BeerOclock
February 5th, 2009, 02:15 PM
Ive got a question that feels like it should be easy but I cant figure it out.

Suppose I have 2d grid of square sprites on the stage, lets say 20 by 20 (400 sprites).
Another sprite moves accross the stage on top of the grid.
The moving sprite and the 400 sprites below it share a common parent.

So heres the question: How do I find out which of the 400 sprites the moving sprite is currently over? And heres an extra wrinkle: I lied, the sprites are not square they are of differing shapes so I cant do a simple math calculation.

All I can come up with is something like hitTestPoint(), but then I would have to call it 400 times wouldnt I? That is probably the most inefficient way to do things.

Is there a function like whatsUnderThisPoint(p : Point) which will return a list of every sprite on the display list that contains p?

Or am I approaching this the wrong way?
Thanks in advance!

TheCanadian
February 5th, 2009, 02:22 PM
Ya know what, there is:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#getObjectsUnderPoint()

You might also look into dropTarget:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Sprite.html#dropTarget

BeerOclock
February 5th, 2009, 02:25 PM
I'm constantly giving people links to the language reference when they ask dumb questions. I guess I just got served!

Thanks lol

TheCanadian
February 5th, 2009, 11:52 PM
Haha no problem ;)