Time for action – animating the notes
Previously, we started an interval using setInterval()
in the startGame()
method. The updateNotes()
method gets called every time the interval expires. This method is responsible for updating the position of all of the note
elements, so they appear to move down the screen:
function updateNotes() { $(".note", $notesPanel).each(function() { var $note = $(this); var top = $note.position().top; if (top <= 200) { // Move the note down top += pixelsPerFrame; $note.css("top", top); if (top + 20 > 200) { // The note hit the bottom of the panel currentNote.note = $note.data("note"); currentNote.time = getCurrentTime(); currentNote.$note = $note; if (practiceMode) pressPianoKey($note.data("note")); } } else...