Groups | Blog | Home
all groups > flash actionscript > may 2005 >

flash actionscript : Linked puzzle pieces


deckarep
5/18/2005 2:44:14 PM
I'm not going to explain word for word on what to do but here's an
idea: Use a recursive function that looks for all linked neigbors.
Then, for each linked neighbor run the function again...and so on and
so on (recursion) until all linked neighbors are into an array. Then
when you select one piece...it'll grab all pieces in that array and
they will all move accordingly.

Depending on how many pieces you have a recursive function may be
slightly slower than just using regular looping constructs...but in
this scenario recursion is the most intuitive approach.

At least to me....

By the way,

You might wanna think about changing your name to something else... ;)
The flash God
5/18/2005 9:09:47 PM
What I want to do is a puzzle where you drag and drop pieces. But I dont want
the pieces to lock when they are drop at their place (like most puzzle i saw on
the web). I want them to snap between each other when they hitTest the right
piece. Then when they are linked, they still are draggable so (like a real
puzzle) you can join pieces that go together and then join two groups of many
pieces together.

The problem is that when i have a group of pieces linked together and I drag
one of them, I want the others to follow it. Anyone have any idea how i could
do it!
kglad
5/19/2005 1:59:21 AM
for that you'll probably want to fake the multi-piece drag. when your
hitTest() is true (ie, two adjacent pieces have been positioned correctly),
check to see if neither has an array of linked pieces. if neither is linked to
anything, create an array and put both pieces in that array: these pieces are
now linked. whenever one is dragged the other will move via a loop (say
setInterval() ) and appear to be dragged.

if only one is in a linkage array, add the other to that linkage array. if
both are in a linkage array, merge the two arrays. again, when any piece from
a linkage array is dragged, the rest of the pieces in that linkage array will
move via a loop and appear to be dragged.
AddThis Social Bookmark Button