AS2: Hittest without movieclip?
I have thousands of simple movieclips on the stage (rectangles), that are being hittested against another rectangle, the problem is I now have so many movieclips it is causing my SWF to playback somewhat choppy.
I cannot do without these MCs, so does anyone know of a way to hitTest purely against the drawn vectors? (The vectors are drawn 开发者_Python百科by actionscript). I have also tried to cache these as bitmap but they are very small rectangles and appear very choppy and ugly when bitmapped.
It would be nice to just treat all the rectangles as one MC and hittest for each individually.
hitTest method itself requires a lot of calculation, that's why when dealing with thousands of collisions you need to minimize the usage of that method or implement your own method for collision detection.
Easy way to detect multiple collisions was described at the book "Flash Hacks" by Sham Bhangal (O'Reilly 2004). The core idea of that method was to add all the movieClips into one container movieClip and then test the collision of that container movieClip with the point (or object). You may search for reprints of this hack on the web.
If that method doesn't suite you, then probably you'll need to deal with rectangle collision detection techniques (and get rid of hitTest). You may read this article which shows the ways to detect collision between axis-aligned bounding box, or AABB and other objects. The detection of collision between oriented bounding boxes, or OBB, is more complex, but you may find and modify existing algorithms. I've used the algorithm from the link above in this OBB collsion detection demo. I've included the source code of it (AS3 not AS2), so you may check that out also.
精彩评论