function check_itv(key) {
if (key.length){
if(key=="left"){
left_itv = setInterval(left,100);
check_left= false;
check_right=true;
check_up=true;
check_down=true;
clearInterval(right_itv);
clearInterval(down_itv);
clearInterval(up_itv);
}
if(key=="right"){
right_itv = setInterval(right,100);
check_left= true;
check_right=false;
check_up=true;
check_down=true;
clearInterval(left_itv);
clearInterval(down_itv);
clearInterval(up_itv);
}
if(key=="up"){
up_itv = setInterval(up,100);
check_left= true;
check_right=true;
check_up=false;
check_down=true;
clearInterval(left_itv);
clearInterval(right_itv);
clearInterval(down_itv);
}
if(key=="down"){
down_itv = setInterval(down,100);
check_left= true;
check_right=true;
check_up=true;
check_down=false;
clearInterval(left_itv);
clearInterval(right_itv);
clearInterval(up_itv);
}
}
}
check_left = true;
check_right = true;
check_up = true;
check_down = true;
left_itv = "";
right_itv = "";
up_itv = "";
down_itv = "";
Try to do shorter and better, Any idea ?
Thanks
var check_left = true;
? Why do you have variables and methods in multiples of 4 and not a single variable for the direction? Etc. – ANeves Aug 16 '12 at 14:33