I've been struggling trying to make a piece in my game move to a specific tile, and after a few seconds move over to a different tile. However, no matter how big I make the delay in setTimeout, it seems to be making it at the same speed always. Is it because I am invoking it inside a function and therefore code executes really fast or is it another thing?
Here's part of the code:
resi = 14;
function return(retnum) {
for (var indexnum:Number = 0; indexnum < allplayerarray.length; indexnum++) {
if (allplayerarray[indexnum]._x == tileset[retnum]._x && allplayerarray[indexnum]._y == tileset[retnum]._y-6) {
resi -= 1;
return true;
}
}
}
function check(arg) {
for (var initiate:Number = 1; initiate <= 9; initiate++) {
var testphase = _root.return(resi);
if (testphase == true) {
_root.return(resi);
}
}
arg._x = _root.tileset[resi]._x;
arg._y = _root.tileset[resi]._y-6;
resi = 14;
}
And here I invoke the function with a delay of 5 seconds inside another function:
setTimeout(_root.check, 5000, chip);