From 5c62de15a4857bb9f9dc4cbca6c0fac14306b736 Mon Sep 17 00:00:00 2001 From: adrien Date: Tue, 27 Aug 2024 02:45:24 +0200 Subject: [PATCH] fixes --- app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app.js b/app.js index 014d618..ce2ebb1 100644 --- a/app.js +++ b/app.js @@ -206,7 +206,7 @@ class Quarter extends Note { } drawShot() { - canvasCtx.drawImage(this.sprite, 0, 34, 35, 67, this.dx, this.dy, 35, 67) + canvasCtx.drawImage(this.sprite, 0, 34, 35, 66, this.dx, this.dy, 35, 66) } explose() { @@ -447,7 +447,7 @@ function resume() { Tone.Transport.start() } -function update() { +function update(time) { noteSprites.forEach(noteSprite => { noteSprite.y += speed }) @@ -463,7 +463,7 @@ function update() { cannonSprites.filter(cannonSprite => cannonSprite.shooting).forEach(cannonSprite => { let noteSprite = noteSprites.find(noteSprite => noteSprite.note == cannonSprite.note) if (noteSprite && !noteSprite.shot) { - playNote(noteSprite.note, noteSprite.velocity, noteSprite.duration) + playNote(noteSprite.note, noteSprite.velocity, time + noteSprite.duration) cannonSprite.impactY = noteSprite.y noteSprite.shot = true window.setTimeout(() => { @@ -476,7 +476,7 @@ function update() { }) } -function playNote(note, velocity=0.7, duration=0) { +function playNote(note, velocity=0.7, stopAt=0) { if(oscillators[note]) return var oscillator = audioCtx.createOscillator() @@ -492,9 +492,9 @@ function playNote(note, velocity=0.7, duration=0) { depth.connect(oscillator.detune) - if (duration) { - oscillator.velocity.gain.setValueCurveAtTime([velocity, velocity/10, velocity/20, 0], audioCtx.currentTime + duration, 0.5) - oscillator.stop(audioCtx.currentTime + duration + 0.6) + if (stopAt) { + oscillator.velocity.gain.setValueCurveAtTime([velocity, velocity/10, velocity/20, 0], stopAt, 0.5) + oscillator.stop(stopAt + 0.5) } else { oscillators[note] = oscillator }