Phaser笔记-Phaser适配WeChat
Posted IT1995
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Phaser笔记-Phaser适配WeChat相关的知识,希望对你有一定的参考价值。
首先将这个大佬的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();
以上是关于Phaser笔记-Phaser适配WeChat的主要内容,如果未能解决你的问题,请参考以下文章