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与小游戏业务的契合度. ...
随机推荐
- 20155331 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20155331 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 使用JDK编译.运行简单的java程序 实验目的与要求: 使用JDK和IDE编译.运行简 ...
- 【转载】漫谈C++:良好的编程习惯与编程要点
原文: 漫谈C++:良好的编程习惯与编程要点 阅读目录 以良好的方式编写C++ class Class with pointer member(s):记得写Big Three static与类 正文 ...
- springboot对security的后端配置
一.Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中配置的Bean,充分利用了Spring ...
- Keil5的设置
目录 编码格式 字体大小 代码颜色 编码格式 有时候用keil打开工程的时候,发现中文注释是乱码的格式,这是因为编码格式方式不对造成的.可以通过设置不同的编码方式来解决. 点击Edit->Con ...
- python--自定义模块
python模块说明:类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才能完成(函数又可以在不 ...
- jmeter执行顺序及作用域规则
1.执行顺序 配置元件 前置处理器 定时器 采样器 后置处理器 断言 监听器 备注: 服务器响应为空的话后三个不执行 作用域内存在采样器时定时器.断言.前置/后置处理器才执行 逻辑控制器和采样器按照在 ...
- CentOS 下 Java 的下载、安装、配置
CentOS 下 Java 的下载.安装.配置 系统: CentOS 7 x86_64 Java 版本: 1.8.0_171 本文将 Java 目录放在 /usr/local/java 文件夹下,读者 ...
- eclipse查看源代码问题
最近分析源代码时,eclipse总是出错,显示org.eclipse.core.runtime.CoreException,解决方法:在builderpath点击 add external jars, ...
- 用EC5/EC6自定义class的区别及用法 -- Phaser3网页游戏框架
custom class EC6 自定义class class Brain extends Phaser.GameObjects.Sprite { constructor (scene, x, y ...
- 如何在 Debian 9 下安装 LEMP 和 WHMCS 7.5
WHMCS 7.5 发布了,它开始支持 PHP 7.2,这里就写个简单的教程记录一下安装方式. 1.准备工作 首先,我们需要按照 在Debian 9 / Debian 8 下使用源安装方式安装 LEM ...