This is the jigsaw topic again.. :D Much thanks for the help you guys lended
several weeks ago to make me (almost) finish this jigsaw puzzle project.
Most of the core mechanism is done, but now it needs some final adjustments,
mostly concerning 'optimizing performance'. Currently I've implemented what
Danny and Hans suggested on earlier threads, which is the use of "Group"
objects that contains piece data and its neighbours.. the piece has a
property referencing a Group and when a piece snaps to another piece, its
Group object 'merge' thus making it easier to detect when the puzzle is done
(which is if there is only 1 Group object left).. it's brilliant Danny! Much
easier to handle the pieces with this method..

now for the problem.. if you see the flash movie i've attached, you'll
notice that when a group of pieces that are connected to each other are
moved sometimes it lags. I've manage to lock down the core problem, which is
that it only lags when you drag a piece located from the left / top most of
the Group. It wont lag if only you drag the right/bottom most of the Group.
The drag method for groups is done customely and it tells the members of the
Group object the piece you're dragging, to move as well. The code:

function dragGroup(what) {
   //move the pressed MC
   sX = _root._xmouse;
   sY = _root._ymouse;
   wX = what._x;
   wY = what._y;
   what.onEnterFrame = function() {
       this._x = _root._xmouse - sX + wX;
       this._y = _root._ymouse - sY + wY;
   }

   //get the other members
   tpcs = this.members.slice();
   //cut out what MC from tpcs
   for(i in tpcs) {
       if(tpcs[i] == what) {
           tpcs.splice(i, 1);
       }
   }

   disti = new Array();
   distj = new Array();
   //move the rest of the members not including 'what' by grid
   //corresponding to 'what'
   for(a = 0; a < tpcs.length; a++) {
       tpcs[a].onEnterFrame = function() {
           disti = this.i - what.i;
           distj = this.j - what.j;
           this._x = what._x + (distj * (kepingW));
           this._y = what._y + (disti * (kepingH));
       }
   }
   delete(tpcs);
   delete(disti);
   delete(distj);
}

this method is located in the Group object, btw. and i think the problem is
located somewhere in the looping part of the algorithm, but unsure where.
It's probably logical that when you move the right/bottom most piece in the
group, it is cut off from the loop and makes the piece on its left / above
to move smoothly... Not sure... anyone have a clue on this issue? Could be
somewhere wrong in my method?

thanks before,
Guntur N. Sarwohadi
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to