[EMAIL PROTECTED] wrote:
Hi
I'm creating a 'snappable' class, that would work with a predefined set of x,y 
pairs or 'hotspots'.
When a dragged movieclip was within a 'offset' distance of any of these 
hotspots it would 'snap to' and stop drag.
The best way of doing this I thought would be to simply pass an array of 
predefined x,y pairs as an object into the class when it was instantiated.
However, having to cycle thru an array, especially if there are a huge number 
of 'hotspots', while dragging doesn't seem very efficient....can anyone suggest 
a better way of approaching this?

theres a fair few spatial partitioning approaches around these days, but i guess you could do something easy with quadtrees. It depends on how many hotspots you have and what shapes the objects are etc..I think the first thing to do is some performance tests to see if checking the whole array is too expensive.

If you do need them then quadtree's are quite simple, basically you divide the screen into 4, then you can recursively subdivide each section, stopping when you think you have a small enough resolution.

Then when you are dragging this clip around you will only need to test for proximity to items contained within certain nodes of the tree, not everything on screen.

I dont know of any AS2 implementations, but its quite fun to code :)

i've found a few references that should help explain :

http://www.gamedev.net/reference/articles/article1303.asp

http://www.ece.eps.hw.ac.uk/~dml/cgonline/hyper00/model/spacediv.html

theres even a paper on macromedia.com that covers quadtrees

http://www.macromedia.com/devnet/director/articles/collision_detection/collision_detection_lingo.pdf

good luck

martin.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to