phaser3微信小遊戲版本-優化
阿新 • • 發佈:2021-08-02
這前寫過一版phaser3微信小遊戲,現在看來,有更好的方案。
擴充套件此方案可以更新的本地快取。
Phaser.Loader.File.prototype.defload = Phaser.Loader.File.prototype.load; Phaser.Loader.File.prototype.onLoad = function (xhr, event) { var localFileOk = ((xhr.responseURL && xhr.responseURL.indexOf('file://') === 0 && xhr.status === 0));var success = !(xhr && xhr.status !== 200) || localFileOk; if (xhr.readyState === 4 && xhr.status >= 400 && xhr.status <= 599){ success = false; } this.state = 12; this.resetXHR(); this.loader.nextFile(this, success); } Phaser.Loader.File.prototype.load = function() { if (this.type == "image") { this.data = new Image(); let self = this; this.data.onload = function() { self.state = 12; self.loader.inflight.delete(self); self.loader.totalComplete++; self.loader.queue.set(self); self.loader.emit("load", self); self.onProcessComplete(); } let src = this.url; this.data.src = src; }else { this.defload(); } }