From 763cfb01f05503fd71a27f409d9dc5fab2a3eefe Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 11 Dec 2016 05:29:21 -0500 Subject: [PATCH] Fix background music stuttering I finally got to reading the SM2 documentation more closely, and saw: > precision can vary between 20 msec to perhaps 0.5 seconds and the > sound's position property will reflect this delta when the > onPosition() callback fires Emphasis on "this.position will reflect this delta". Anyway, this new system should have significantly less noticeable stuttering. --- js/battle.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/battle.js b/js/battle.js index ffc76d51d..7ea14bac5 100644 --- a/js/battle.js +++ b/js/battle.js @@ -92,8 +92,8 @@ var BattleSoundLibrary = (function () { // suppress crash return (this.bgmCache[url] = this.soundPlaceholder); } - this.bgmCache[url].onposition(loopend, function () { - this.setPosition(loopstart); + this.bgmCache[url].onposition(loopend, function (evP) { + this.setPosition(this.position - (loopend - loopstart)); }); return this.bgmCache[url]; };