代码拉取完成,页面将自动刷新
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
/**
* A brief explanation for "project.json":
* Here is the content of project.json file, this is the global configuration for your game, you can modify it to customize some behavior.
* The detail of each field is under it.
{
"project_type": "javascript",
// "project_type" indicate the program language of your project, you can ignore this field
"debugMode" : 1,
// "debugMode" possible values :
// 0 - No message will be printed.
// 1 - cc.error, cc.assert, cc.warn, cc.log will print in console.
// 2 - cc.error, cc.assert, cc.warn will print in console.
// 3 - cc.error, cc.assert will print in console.
// 4 - cc.error, cc.assert, cc.warn, cc.log will print on canvas, available only on web.
// 5 - cc.error, cc.assert, cc.warn will print on canvas, available only on web.
// 6 - cc.error, cc.assert will print on canvas, available only on web.
"showFPS" : true,
// Left bottom corner fps information will show when "showFPS" equals true, otherwise it will be hide.
"frameRate" : 60,
// "frameRate" set the wanted frame rate for your game, but the real fps depends on your game implementation and the running environment.
"noCache" : false,
// "noCache" set whether your resources will be loaded with a timestamp suffix in the url.
// In this way, your resources will be force updated even if the browser holds a cache of it.
// It's very useful for mobile browser debugging.
"id" : "gameCanvas",
// "gameCanvas" sets the id of your canvas element on the web page, it's useful only on web.
"renderMode" : 0,
// "renderMode" sets the renderer type, only useful on web :
// 0 - Automatically chosen by engine
// 1 - Forced to use canvas renderer
// 2 - Forced to use WebGL renderer, but this will be ignored on mobile browsers
"engineDir" : "frameworks/cocos2d-html5/",
// In debug mode, if you use the whole engine to develop your game, you should specify its relative path with "engineDir",
// but if you are using a single engine file, you can ignore it.
"modules" : ["cocos2d"],
// "modules" defines which modules you will need in your game, it's useful only on web,
// using this can greatly reduce your game's resource size, and the cocos console tool can package your game with only the modules you set.
// For details about modules definitions, you can refer to "../../frameworks/cocos2d-html5/modulesConfig.json".
"jsList" : [
]
// "jsList" sets the list of js files in your game.
}
*
*/
// fetch封装,作用:前后端通信
// body是给服务器的json对象,服务器返回json
// 根据json中code码,如果为0调用fn,否则后端出错,调用errorfn
// 最后的props不限个数,将传给被调用的函数处理
const Fetch = function(url, body, fn, errorfn, ...props) {
fetch(url + "?" + body, {
method: "get",
headers: {
'Content-Type': 'application/json'
},
})
.then(function(response) {
let j = response.json();
return j;
})
.then(function(data) {
console.log(data);
if (data.code) {
// 如果有报错,打印信息,终止调用
errorfn(...props);
} else {
fn(data['data'], ...props);
}
});
}
// // fetch改成XHR了,调用方法不变!(但最后不接收多余参数了)
// const Fetch = function(url, body, fn, errorfn) {
// var xhr = new XMLHttpRequest();
// xhr.open('GET', url + "?" + body);
// // xhr.setRequestHeader('content-type', 'application/json');
// xhr.send();
// //监听服务器响应
// xhr.onreadystatechange = function() {
// if (xhr.readyState == 4 && xhr.status == 200) {
// let data = JSON.parse(xhr.responseText);
// console.log(data);
// if (data.code) {
// // 如果有报错,打印信息,终止调用
// errorfn();
// } else {
// fn(data['data']);
// }
// }
// }
// }
cc.game.onStart = function() {
var sys = cc.sys;
if (!sys.isNative && document.getElementById("cocosLoading")) //If referenced loading.js, please remove it
document.body.removeChild(document.getElementById("cocosLoading"));
// Pass true to enable retina display, on Android disabled by default to improve performance
//cc.view.enableRetina(sys.os === sys.OS_IOS ? true : false);
cc.view.enableRetina(true);
// Disable auto full screen on baidu and wechat, you might also want to eliminate sys.BROWSER_TYPE_MOBILE_QQ
if (sys.isMobile &&
sys.browserType !== sys.BROWSER_TYPE_BAIDU &&
sys.browserType !== sys.BROWSER_TYPE_WECHAT) {
cc.view.enableAutoFullScreen(true);
}
// 关闭调试信息
cc.director.setDisplayStats(false);
// Adjust viewport meta
cc.view.adjustViewPort(true);
// Uncomment the following line to set a fixed orientation for your game
// cc.view.setOrientation(cc.ORIENTATION_PORTRAIT);
// Setup the resolution policy and design resolution size
cc.view.setDesignResolutionSize(400, 800, cc.ResolutionPolicy.SHOW_ALL);
// The game will be resized when browser size change
cc.view.resizeWithBrowserSize(true);
//load resources
cc.LoaderScene.preload(g_resources, function() {
document.body.removeChild(document.getElementsByClassName("loader")[0]);
cc.director.runScene(new LoginScene());
}, this);
};
cc.game.run();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。