我对 JS 和 JQuery 有点陌生。我正在尝试在 JQuery 中创建一种 GuitarHero 游戏,但音符并没有顺利下降我所做的基本上是setTimeout()
在一个循环中调用 - 每个都有不同的超时(以数组形式给出 - “歌曲 scipt”如果你愿意)。代码如下所示:
while(counter < curSong.numNotes){
// set the parameters sent to runCreateNote
runCreateNote(counter, margin, entity, interval, name);
counter++;
}
runCreateNote
调用时setTimeout()
(用于范围目的)
这是动画代码:
noteBall.animate({
top: (noteBall.parent().height() - noteBall.height()*2) + 'px'
}, {
duration: fallingtime,
queue: false,
easing: "linear",
step: function() {
checkStep(id);
},
complete: function() {
reachBottom(id);
}
});
function checkStep(id){
var noteBall = $("#" + id);
var name = id.substring(0,1);
if (name == "R"){
if (isInRange(noteBall)){
isRedIn = true;
} else {
isRedIn = false;
}
}
if (name == "B"){
if (isInRange(noteBall)){
isBlueIn = true;
} else {
isBlueIn = false;
}
}
if (name == "G"){
if (isInRange(noteBall)){
isGreenIn = true;
} else {
isGreenIn = false;
}
}
if (name = "O"){
if (isInRange(noteBall)){
isOrangeIn = true;
} else {
isOrangeIn = false;
}
}
}
我不知道是否有任何代码是相关的,但我只是想表明动画看起来不太重(我认为它会运行顺利)
我错过了一些关键原则吗?