phaser3微信小游戏2

之前介绍过phaser3微信小游戏适配(只需2步)

添加微信小游戏适配器(官网上下载最新的weapp-adapter即可)

修改phaser加载image的方式需要修改(由于微信小游戏不支持blob)

添加适配器就不用说了,修改加载image的加载方式(重写是最好的,当然也可以改源码,然后编译)

// wechat适配器的performance的存在问题,不应该除以1000
window.performance.now = function() {
return Date.now()
};

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();
}
}

 

posted @ 2021-08-02 18:15  wanhong  阅读(545)  评论(0编辑  收藏  举报