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

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

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

官文给的是


// 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
分享给朋友:

相关文章

工作站T7810重装系统注意事项

工作站T7810重装系统注意事项

        dell的工作站T7810(Dell Precision Tower 7810)由于使用了磁盘阵列技术,在重装系统时发现会找不到任何驱动设备。...

AUTOCAD2018无法启动及启动后界面闪烁

AUTOCAD2018无法启动及启动后界面闪烁

AUTOCAD2018安装完毕后启动时无法进入主界面就报错“autocad application 已停止工作”。 用管理员身份或者兼容模式运行,会在进入主界面之前自动退出程序。 通过visualsutio调试,发现问题出现在nvwgf...

ubuntu 安装mysql

ubuntu 安装mysql

sudo apt-get install mysql-server sudo apt isntall mysql-client sudo apt install libmysqlclient-dev 检测是否安装成功: sudo n...

ubuntu QT5.11.1链接MYSQL数据库出错的问题。

ubuntu QT5.11.1链接MYSQL数据库出错的问题。

编译后链接数据库时提示 QSqlDatabase: QMYSQL driver not loaded QSqlDatabase: available drivers: QSQLITE,QMYSQL……...

BBR+BBR魔改+锐速一键脚本 for Centos/Debian/Ubuntu

BBR+BBR魔改+锐速一键脚本 for Centos/Debian/Ubuntu

此文为引用文。 支持系统:Centos 6+/Debian 8+/Ubuntu 14+,BBR魔改版不支持Debian 8 wget -N --no-check-certificate...

cocos creator的Action类整理

cocos creator的Action类整理

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