I've got aplication 'self-sliding-puzzle' with AI on it etc. I will use it to make some cool portfolio gallery.
I've got one method that just animates cube:
this.animateSelection = function(direction,time)
{
if (time===undefined) this.time=150;
this.moveDistance=this.cubeSize+this.spacing;
switch (direction)
{
//move right
case 'r': $('#' + selectionName).transition({ x: '+=' +this.moveDistance +'px' },this.time);
break;
//move down
case 'd': $('#' + selectionName).transition({ y: '+=' +this.moveDistance +'px' },this.time);
break;
//move left
case 'l': $('#' + selectionName).transition({ x: '-=' +this.moveDistance +'px' },this.time);
break;
//move up
case 'u': $('#' + selectionName).transition({ y: '-=' +this.moveDistance +'px' },this.time);
break;
//if wrong direction is given
default: return false;
}
return true;
}
Everything works cool when I call it single time.
But problem is:
when i do
myClass.animateSelection('d');
alert('bla bla bla');
alert is show before animation is done
My main AI loop executes in 50ms and manage about 200 moves, so calls method. I want that method to hold executing of loop till ANIMATION is done.
Callback dont make it. animation Method is used in many different situation and by various other methods. Its impossible to make it fit that way IMO.