Friday, 6 September 2013

Slow down method execution so animation appears in flash

Slow down method execution so animation appears in flash

I have a method to swap two pieces in Bejeweled, but the animated swap
doesn't appear to the user when they make a swap with no matches.
I.e. When the user tries to swap a jewel and no matches occur, the jewel
stays stationary. What should happen is the jewel swaps positions,
realises there isn't a match and swaps back.
I believe the issue is that the swaps are happening almost instantly if
there isn't a match and there is no animation for the user.
How can I slow down the execution time of the second swap (i.e. the swap
back) so the animation of the swap occurs?
// start animated swap of two pieces
public function makeSwap(piece1,piece2:Piece)
{
swapPieces(piece1,piece2);
//check to see if move works
if (lookForMatches().length == 0)
{
swapPieces(piece1,piece2); //Swap the piece back
}
else
{
isSwapping = true;
}
}
// swap two pieces
public function swapPieces(piece1,piece2:Piece)
{
// swap row and col values
var tempCol:uint = piece1.col;
var tempRow:uint = piece1.row;
piece1.col = piece2.col;
piece1.row = piece2.row;
piece2.col = tempCol;
piece2.row = tempRow;
// swap grid positions
grid[piece1.col][piece1.row] = piece1;
grid[piece2.col][piece2.row] = piece2;
}

No comments:

Post a Comment