phaser3 微信小游戏若干问题
用phasr3开发微信小游戏的话, 需要修改源码的地方不多。
1:微信小游戏不支持xml,需要装个DOMParser http://club.phaser-china.com/topic/5b1276a0484a53dd723f42ff
2:图片加载方式需要修改,不好重写代码,需要修改源码
var ImageFile = new Class({
Extends: File,
initialize:
function ImageFile (loader, key, url, xhrSettings, frameConfig)
{
this.isWX = typeof wx !== "undefined";
var extension = 'png';
var normalMapURL;
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
url = GetFastValue(config, 'url');
normalMapURL = GetFastValue(config, 'normalMap');
xhrSettings = GetFastValue(config, 'xhrSettings');
extension = GetFastValue(config, 'extension', extension);
frameConfig = GetFastValue(config, 'frameConfig');
}
if (Array.isArray(url))
{
normalMapURL = url[1];
url = url[0];
}
var fileConfig = {
type: 'image',
cache: loader.textureManager,
extension: extension,
responseType: 'arraybuffer',
key: key,
url: url,
xhrSettings: xhrSettings,
config: frameConfig
};
File.call(this, loader, fileConfig);
// Do we have a normal map to load as well?
if (normalMapURL)
{
var normalMap = new ImageFile(loader, this.key, normalMapURL, xhrSettings, frameConfig);
normalMap.type = 'normalMap';
this.setLink(normalMap);
loader.addFile(normalMap);
}
},
/**
* Called automatically by Loader.nextFile.
* This method controls what extra work this File does with its loaded data.
*
* @method Phaser.Loader.FileTypes.ImageFile#onProcess
* @since 3.7.0
*/
onProcess: function ()
{
let url = this.__url;
this.state = CONST.FILE_PROCESSING;
this.data = new Image();
this.data.crossOrigin = this.crossOrigin;
var _this = this;
this.data.onload = function ()
{
if (!this.isWX) {
File.revokeObjectURL(_this.data);
_this.onProcessComplete();
} else {
this.addToCache();
}
};
this.data.onerror = function ()
{
if (!this.isWX) {
File.revokeObjectURL(_this.data);
} else {
console.log("||||||");
}
_this.onProcessError();
};
if (this.isWX) {
this.data.src = url;
} else {
File.createObjectURL(this.data, this.xhrLoader.response, 'image/png');
}
},
/**
* Adds this file to its target cache upon successful loading and processing.
*
* @method Phaser.Loader.FileTypes.ImageFile#addToCache
* @since 3.7.0
*/
addToCache: function ()
{
var texture;
var linkFile = this.linkFile;
if (linkFile && linkFile.state === CONST.FILE_COMPLETE)
{
if (this.type === 'image')
{
texture = this.cache.addImage(this.key, this.data, linkFile.data);
}
else
{
texture = this.cache.addImage(linkFile.key, linkFile.data, this.data);
}
this.pendingDestroy(texture);
linkFile.pendingDestroy(texture);
}
else if (!linkFile)
{
texture = this.cache.addImage(this.key, this.data);
this.pendingDestroy(texture);
}
}
});
3: 边界面部导致微信小游戏的点击事件失效, window.pageXOffset为undefined 修改源码或修改适配器都可以
updateBounds: function ()
{
var bounds = this.bounds; var clientRect = this.canvas.getBoundingClientRect(); bounds.x = clientRect.left + (window.pageXOffset - document.documentElement.clientLeft || 0);
bounds.y = clientRect.top + (window.pageYOffset - document.documentElement.clientTop || 0);
bounds.width = clientRect.width;
bounds.height = clientRect.height;
},
phaser3 微信小游戏若干问题的更多相关文章
- phaser3 微信小游戏入门
phaser与eget, laya, pixi.js本质上没什么区别. 都是渲染引擎. 其它的都是配角. phaser的特点是.代码容易理解 功能比较全面. 个人比较喜欢phaser的地方 twe ...
- Egret白鹭开发微信小游戏排行榜功能
推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 我的个人博客 最近事情特别多,今天终于实现了排行榜功能,记录下来大家一起学习学习. 一.调用默认排行榜 首先我们需要了解: 1.白鹭开 ...
- 没玩过这些微信小游戏你就out了
你确定没玩过下面这些微信小游戏?是不是有点out了?赶紧添加微信号kangfuyk,回复H5马上畅玩! 当然了,扫一下二维码关注后回复H5更快捷噢! 微信小游戏列表,持续更新中 辨色大比拼!心理游戏 ...
- 【转】微信小游戏接入Fundebug监控
在SegmentFault上看到Fundebug上线小游戏监控,刚好最近开始玩微信小游戏,于是尝试接入试了一下. 接入方法 创建项目的时候选择左下角的微信小游戏图标. 点击继续进入接入插件页面. 第三 ...
- 【转】Fundebug上线微信小游戏错误监控!支持自动截屏!
摘要: Fundebug竭诚为你的小游戏保驾护航. 想必大家都玩过"跳一跳"吧?刷排行榜的感觉是不是很好啊!还有"知乎答题王"呢,在智力上碾压老铁简直太棒了! ...
- 【转】利用 three.js 开发微信小游戏的尝试
前言 这是一次利用 three.js 开发微信小游戏的尝试,并不能算作是教程,只能算是一篇笔记吧. 微信 WeChat 6.6.1 开始引入了微信小游戏,初期上线了一批质量相当不错的小游戏.我在查阅各 ...
- 微信小游戏开发之四:使用three.js引擎
一.前言 微信小游戏中最魔性的'跳一跳'就是基于three.js 引擎开发的 源码放到github上了:GitHub地址 请自行下载. 二.下载 three.min.js 打开页面,复制代码到本地 ...
- 微信小游戏开发Canvas资源汇总
Demo: 微信小程序demo组件:股票分时图 微信小程序小组件:仿直播点赞气泡效果,基于Canvas 优质demo推荐:二维码生成器:使用canvas与纯JS版二维码生成 微信小程序学习用完整dem ...
- 微信小游戏爆款秘笈 数据库MongoDB攻略篇
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯云数据库 TencentDB 发表于云+社区专栏 随着微信小游戏的爆发,越来越多开发者关注到MongoDB与小游戏业务的契合度. ...
随机推荐
- Gulp的安装配置过程和一些小坑
谈谈gulp. 项目尾声,老师叫我去熟悉一下grunt前端自动化工具,第一次知道这种东西,我就查各种资料啊,发现grunt已经‘过时’了,大家都用gulp和webpack.我当然选择了配置最简单的gu ...
- makefile中重载与取消隐藏规则示例
学习<跟我一起写Makefile-陈皓>后一直不懂,如何重载或取消隐藏规则 为了博客版面整洁,何为隐藏规则,Makefile基本规则编写等基础支持请自行百度. 需要声明的是:这些知识可能在 ...
- PhoneGap3.2安装步骤
1.首选安装好JDK.Android SDK.Ant 配置如下: 系统环境变量 ANDROID_HOME Value: C:\Development\adt-bundle\ ...
- 【转载】CPU阿甘
原文:CPU阿甘 前言 上帝为你关闭了一扇门,就一定会为你打开一扇窗这句话来形容我最合适不过了.我是CPU, 他们都叫我阿甘, 因为我和<阿甘正传>里的阿甘一样, 有点傻里傻气的.上帝 ...
- CF 833 B. The Bakery
B. The Bakery http://codeforces.com/contest/833/problem/B 题意: 将一个长度为n的序列分成k份,每份的cost为不同的数的个数,求最大cost ...
- Raft 一致性协议算法 《In search of an Understandable Consensus Algorithm (Extended Version)》
<In search of an Understandable Consensus Algorithm (Extended Version)> Raft是一种用于管理日志复制的一致性算 ...
- Android 8.0 NavigationBar 颜色问题。
1. packages/SystemUI/src/com/android/systemui/statusbar/phone/LightBarController.java public void on ...
- Struts2(一.基本介绍,环境搭建及需求分析)
Struts2框架开发 前言 开发工具:eclipse struts1:老项目使用较多,维护时需要用到 struts2:新项目使用较多 一.特点 1. 无侵入式设计 struts2 与 struts ...
- 【bzm-Random CSV Data Set Config】 -jmeter - 文件中随机取参的方法,(插件自带)
文件中随机取参数的方法 Random CSV Data Set Config
- HBASE理论篇
1.Hbase是什么 HBase是一种构建在HDFS之上的分布式.面向列的存储系统.在需要实时读写.随机访问超大规模数据集时,可以使用HBase. 尽管已经有许多数据存储和访问的策略和实现方法,但事实 ...