[Flashcoders] Q:creating a 'snappable' class

2006-02-03 Thread bitstreams
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 efficientcan anyone suggest 
a better way of approaching this?

Thanks in advance
Jim Bachalo

[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca

"...all improvisation is life in search of a style."
 - Bruce Mau,'LifeStyle'
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Q:creating a 'snappable' class

2006-02-03 Thread Dimitrios Bendilas

Hi Jim,

Are these hotspots "connected" to each other by arising from one single 
function?
Like, are they equally spaced, (as on a grid), follow the perimeter of a 
circle or

any other math function?

My guess would be no, so...

There can't be any way other than looping through hotspots to see if you are 
near one.

One thing that might be of help though is Grand Skinner's Proximity class.
It might be able to save you lots of calculations, since you could only 
check for hotspots

that are near a specified area. You might want to check that out.

Just a thought...

Dimitrios Bendilas

- Original Message - 
From: <[EMAIL PROTECTED]>

To: 
Sent: Friday, February 03, 2006 10:32 PM
Subject: [Flashcoders] Q:creating a 'snappable' class



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 efficientcan 
anyone suggest a better way of approaching this?


Thanks in advance
Jim Bachalo

[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca

"...all improvisation is life in search of a style."
- Bruce Mau,'LifeStyle'
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders





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


Re: [Flashcoders] Q:creating a 'snappable' class

2006-02-03 Thread Martin Wood



[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 efficientcan 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