当前位置:首页 > 技术手札 > 正文内容

cocos creator学习笔记之loadResDir资源加载和调用

秋风渡红尘6年前 (2019-10-27)技术手札3099

官文给的是


// load the texture (resources/imgs/cocos.png) and the corresponding sprite frame
cc.loader.loadResDir('imgs/cocos', function (err, assets) {
    if (err) {
        cc.error(err);
        return;
    }
    var texture = assets[0];
    var spriteFrame = assets[1];
});

// load all textures in "resources/imgs/"
cc.loader.loadResDir('imgs', cc.Texture2D, function (err, textures) {
    var texture1 = textures[0];
    var texture2 = textures[1];
});

// load all JSONs in "resources/data/"
cc.loader.loadResDir('data', function (err, objects, urls) {
    var data = objects[0];
    var url = urls[0];
});


但是没有足够细致地描述资源的获取使用。 比如从加载的资源中读取某个文件abc.json,不知道怎么调用。 实际上资源的加载是按文件名的命名排行顺序来获得数组的。如果abc.json是在第三位,则应该是res[2]数组成员。 为防止文件越来越多导致混乱,可以用switch(resJson[i].name)来和文件名匹配。

扫描二维码推送至手机访问。

版权声明:本文由咿呀贝发布,如需转载请注明出处。

本文链接:https://yiyabei.cn/?id=47

标签: cocoscreator
分享给朋友:

相关文章

UBUNTU 安装owncloud

UBUNTU 安装owncloud

wget -nv https://download.owncloud.org/download/repositories/production/Ubuntu_16.04/Release.key -O Release.key apt-key...

ubuntu把iso镜像文件添加为更新源

ubuntu把iso镜像文件添加为更新源

环境:vmware12 + win7物理机 + ubuntu16.04虚拟机 iso是用vm直接挂载到ubuntu的,其实是想用iso来升级系统,结果不知道怎么执行升级,反而是一大堆问题。 正确添加源的方法是:...

cocos creator的Action类整理

cocos creator的Action类整理

文章来源:https://blog.csdn.net/cchgood/article/details/80930764 Action类 Action类是所有动作类型的基类  并且Action有两个类别  1、...

cocos creator动态设置label导致F12调试undefined

cocos creator动态设置label导致F12调试undefined

新手上路,想动态添加 label[i].string = text[i]; 所以层级管理器只建立了一个空节点LabelParent; 想把label[i]设置setparent(LabelParen...

cocos creator使用typescrip模板至export和import

cocos creator使用typescrip模板至export和import

export default XX 和 import XX from '...' 搭配。 export XX 和 import {XX} from...

仍在连接中, 请给 MCU 上电...

仍在连接中, 请给 MCU 上电...

雪藏多年的单片机开发板,最近心血来潮,拿出来耍一下,以前是win7玩的,现在在win10上操作,上网找的WIN10系统PL2303驱动。 结果在下载固件的时候,提示: 仍在连接中, 请给 MCU 上电......