####以下是针对1.0.4版本的适配方案(1.1的教程等我升级项目到1.1的时候会更新的)
1.因为引擎本身不支持构建到QQ小游戏。所以我们先构建出来一个微信小游戏的文件夹
2.使用QQ小游戏开发者工具打开我们的项目,运行。注意如果微信小游戏有子域的话。先去game.json里去把openDataContext属性改成空。因为子域可能会报错哦。我们先屏蔽掉子域。
3.不出以意料的话会报错 System not defind
4.打开我们的src/system.bundle.js这个文件,该文件是压缩后的js文件。为了方便阅读,我们使用这个网站将这段代码转化成可读的格式
http://tool.sufeinet.com/Code/Gzip.aspx
5.接着我们搜索这段代码
function(t) {
const e = t.System;
s(e);
const n = e.constructor.prototype,
r = e.constructor,
o = function() {
r.call(this),
s(this)
};
let i;
function c() {
i = null
}
function s(t) {
t.registerRegistry = Object.create(null)
}
o.prototype = n,
e.constructor = o;
const u = n.register;
n.register = function(t, e, n) {
if ("string" != typeof t) return u.apply(this, arguments);
const r = [e, n];
return this.registerRegistry[t] = r,
i || (i = r, setTimeout(c, 0)),
u.apply(this, arguments)
};
6.在 function(t) { 后边追加如下代码
if(!t.parent){
window.System = t.System;
}
最后的成品就是如下代码
function(t) {
if(!t.parent){
window.System = t.System;
}
const e = t.System;
s(e);
const n = e.constructor.prototype,
r = e.constructor,
o = function() {
r.call(this),
s(this)
};
let i;
function c() {
i = null
}
function s(t) {
t.registerRegistry = Object.create(null)
}
o.prototype = n,
e.constructor = o;
const u = n.register;
n.register = function(t, e, n) {
if ("string" != typeof t) return u.apply(this, arguments);
const r = [e, n];
return this.registerRegistry[t] = r,
i || (i = r, setTimeout(c, 0)),
u.apply(this, arguments)
};
7.保存修改好的js文件,不出意外的话就可以跑起来。
8.此时游戏里cc.sys.platform == cc.sys.WECHAT_GAEM是true。环境会被认为是微信环境
9.我们打开main.js。作出如下的修改
var onStart = function () {
window._CCSettings = undefined;
cc.loader.downloader._subpackages = settings.subpackages;
cc.view.enableRetina(true);
cc.view.resizeWithBrowserSize(true);
//在launchScene面前添加底下这句话。这样子游戏运行的时候就可以判断为QQ小游戏啦。
cc.sys.platform = cc.sys.QQ_PLAY;
var launchScene = settings.launchScene;
10.做完这些操作后,我们记得提交这2个文件到自己的git仓库里,以后每次构建新版本后,这个2个文件都会被还原。此时使用git重置一下这2个文件就好啦。
参考来源于论坛里其他人的帖子,感谢: