From 837d5774fe4e2ca255b623d02b5e843eb2584301 Mon Sep 17 00:00:00 2001 From: John Edvard Reiten Date: Mon, 12 Sep 2022 19:10:53 +0900 Subject: [PATCH] fix: Make proper variables and remove unused code from Sprite class --- src/kontra.js | 18 ------------------ src/sound.js | 2 +- src/zzfx.js | 11 ++++++----- src/zzfxm.js | 4 ++-- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/kontra.js b/src/kontra.js index a17ab13..09992c6 100644 --- a/src/kontra.js +++ b/src/kontra.js @@ -587,24 +587,6 @@ class Sprite extends GameObject { } = {}) { super.init({ image: t, width: e, height: i, ...s }); } - get animations() { - return this._a; - } - set animations(t) { - let e, i; - for (e in ((this._a = {}), t)) - (this._a[e] = t[e].clone()), (i = i || this._a[e]); - (this.currentAnimation = i), - (this.width = this.width || i.width), - (this.height = this.height || i.height); - } - playAnimation(t) { - (this.currentAnimation = this.animations[t]), - this.currentAnimation.loop || this.currentAnimation.reset(); - } - advance(t) { - super.advance(t), this.currentAnimation && this.currentAnimation.update(t); - } draw() { this.image && this.context.drawImage( diff --git a/src/sound.js b/src/sound.js index 65cd473..adfd620 100644 --- a/src/sound.js +++ b/src/sound.js @@ -3,7 +3,7 @@ import { zzfxM } from './zzfxm'; let myAudioNode = null; let isPlaying = false; -let audioContext = zzfxX; +let audioContext = window.zzfxX; export const getIsPlaying = () => { return isPlaying; diff --git a/src/zzfx.js b/src/zzfx.js index 163fd4b..4558ea8 100644 --- a/src/zzfx.js +++ b/src/zzfx.js @@ -1,12 +1,13 @@ // zzfxV - global volume -zzfxV = 0.3; +const zzfxV = 0.3; // zzfxR - global sample rate -zzfxR = 44100; +const zzfxR = 44100; +window.zzfxR = zzfxR; // zzfxX - the common audio context -zzfxX = new (window.AudioContext || webkitAudioContext)(); -sfxContext = new (window.AudioContext || webkitAudioContext)(); +window.zzfxX = new (window.AudioContext || webkitAudioContext)(); +const sfxContext = new (window.AudioContext || webkitAudioContext)(); // zzfx() - the universal entry point -- returns a AudioBufferSourceNode export const zzfx = (...t) => zzfxP(sfxContext, zzfxG(...t)); @@ -22,7 +23,7 @@ export const zzfxP = (ctx, ...t) => { }; // zzfxG() - the sound generator -- returns an array of sample data -zzfxG = ( +window.zzfxG = ( q = 1, k = 0.05, c = 220, diff --git a/src/zzfxm.js b/src/zzfxm.js index b374296..41009ce 100644 --- a/src/zzfxm.js +++ b/src/zzfxm.js @@ -23,7 +23,7 @@ export const zzfxM = (n, f, t, e = 125) => { q = 0, s = 1, v = {}, - w = ((zzfxR / e) * 60) >> 2; + w = ((window.zzfxR / e) * 60) >> 2; for (; s; k++) (R = [(s = a = d = m = 0)]), t.map((e, d) => { @@ -55,7 +55,7 @@ export const zzfxM = (n, f, t, e = 125) => { v[[c, g]] || ((l = [...n[c]]), (l[2] *= 2 ** ((g - 12) / 12)), - g > 0 ? zzfxG(...l) : []))); + g > 0 ? window.zzfxG(...l) : []))); } m = G; });