自定义文件(*.data)放在resources目录下,CocoCreator不会自动发布到最终的资源目录下吗?
1、data文件放在assets/resources/data/all.data
2、报错:CCDebugger.js:367 Sorry can not load ‘7002’ because it is not placed in the ‘resources’ folder.
3、加载触发:
doLoad: function () {
cc.loader.addDownloadHandlers({
‘data’: arrayBufferHandler
});
cc.loader.load({
url: cc.url.raw("data/all.data"),
id: "data"
}, function (err, data) {
console.log("errerrerrerrerr===", err);
console.log("datadatadatadata===", data);
});
},
4、加载器:
var arrayBufferHandler = function (item, callback) {
var url = item.url;
var xhr = cc.Pipeline.getXMLHttpRequest();
xhr.open(“GET”, url, true);
xhr.responseType = “arraybuffer”;
xhr.onload = function (oEvent) {
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var result = new Uint8Array(arrayBuffer);
// 任何需要的处理
callback(null, result);
} else {
callback(errorMessage); // 第一个参数需要传递错误信息
}
}
// 错误处理
xhr.onerror = function () {
console.error(“Load data failed!”);
};
xhr.send(null);
};