首先将这个大佬的Github下载下来,他已经做好了适配
GitHub - eastecho/WeChatGame-phaser: A demo running phaser.js in WeChat game platform.
用微信开发工具创建一个小游戏项目。
将git上下载的包放到libs/gamelibs
在main.js中添加:
import BootState from "./states/BootState";
import PreLoadState from "./states/PreLoadState";
/**
* Import Phaser dependencies using `expose-loader`.
* This makes then available globally and it's something required by Phaser.
* The order matters since Phaser needs them available before it is imported.
*/
window.PIXI = require('libs/gamelibs/pixi.min.js')
window.p2 = require('libs/gamelibs/p2.min.js')
window.Phaser = require('libs/gamelibs/phaser-split.min.js')
window.scrollTo = function() {}
/**
* Create a new Phaser game instance.
* And render a single sprite so we make sure it works.
*/
let phGame;
export default class Main {
constructor(){
let {windowWidth, windowHeight} = wx.getSystemInfoSync();
const conf = {
width: windowWidth,
height: windowHeight,
canvas: canvas,
renderer: Phaser.WEBGL,
transparent: false,
antialias: false,
scaleMode: Phaser.ScaleManager.EXACT_FIT,
state: { preload: this.preload, create: this.create, update: this.update, pointer: this.pointDown },
}
phGame = new Phaser.Game(conf);
}
preload(){
}
create(){
}
}
game.js改成如下:
import './js/libs/weapp-adapter'
import './js/libs/symbol'
import Main from './js/main'
new Main();