I'm having some troubles when animating the popular Simon Says game. Here's what I'm doing:
squence = new Array();
colors = ["#green", "#red", "#yellow", "#blue"];
function add_sequence() {
var number = Math.random();
number = number * (4-1);
number = number.toFixed(0);
sequence.push(colors[number]);
for (var i = 0; i < sequence.length; i++) {
anim(sequence[i]);
};
}
function anim(id){
$(id).animate({
opacity: 0.3,
duration: 300
}, function(){
$(id).animate({
opacity: 0
}, 300);
});
}
The logic of the game is working, but I can't make the lights animate one by one. They just animate all at the same time.
I've tried with setTimeout()
, but I can't get it work.