直接上代码 复制项目直接可用
我将官方文档中的http 用js 单利的模式 改了下
var httpUtils = cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
},
statics: {
instance: null
},
// use this for initialization
onLoad: function () {
},
httpGets: function (url, callback) {
var xhr = cc.loader.getXMLHttpRequest();
xhr.onreadystatechange = function () {
if