cc.Director与 资源加载策略

cc.Director对象

1:游戏里面控制管理整个游戏全局对象,包括了场景切换等,为cc.Director对象;

2:导演对象全局只有一个cc.director,大写的为类, 小写的cc.director为全局的导演对象;

3: cc.director来获取导演对象实例;

4: 游戏中各种管理对象都可以通过cc.director获取,比如物理引擎管理,Action管理, 碰撞检测管理等;

常用接口

1: getWinSize: 适配后的逻辑大小;

2: getWinSizeInPixels: 获取窗口的像素大小;

3: getScene: 获取当前的逻辑场景,场景对象下面是Canvas;

4: setDisplayStats: 是否显示左下角FPS信息;

5: getCollisionManager: 获取碰撞检测管理对象;

6: getPhysicsManager :获取物理引擎管理对象;

7:loadScene(scene_name):加载场景,场景的名字,系统会加载对应的场景

8:preloadScene(scene_name):预加载场景

    goto_roadmap : function() {cc.director.loadScene("roadmap_scene");},

资源加载策略

1: h5资源加载的过程:

(1)从服务器上下载来来资源,并把资源加载到内存中,所以你在做h5游戏,你要把你当前游戏中要用到的资源先加载下来,否者的话,你在运行的时候去加载就来不及了(h5卡住);

2:三种资源加载策略:

1>: h5的小游戏:采用全部提前绑定好所有的资源。编写预加载脚本preload.js, 将要加载的资源手动关联到第一个启动的场景上面;

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlcc.Class({extends: cc.Component,properties: {// foo: {//     // ATTRIBUTES://     default: null,        // The default value will be used only when the component attaching//                           // to a node for the first time//     type: cc.SpriteFrame, // optional, default is typeof default//     serializable: true,   // optional, default is true// },// bar: {//     get () {//         return this._bar;//     },//     set (value) {//         this._bar = value;//     }// },img_array: {type: cc.SpriteFrame,default: [],},atlsa_array: {type: cc.SpriteAtlas,default: [],},sound_array: {url: cc.AudioClip,default: [],},prefab_array: {type: cc.Prefab,default: [],},},// LIFE-CYCLE CALLBACKS:// onLoad () {},start () {},// update (dt) {},
});

图片多,可以使用图集打包方式。

2>: 添加等待界面,预加载下一个场景,然后再进行切换,提前关联好下一个场景要的资源;

cc.loader.onProgress = function ( completedCount, totalCount,  item ){

console.log("completedCount:" + completedCount + ",totalCount:" + totalCount );         };

// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.htmlcc.Class({extends: cc.Component,properties: {// foo: {//     // ATTRIBUTES://     default: null,        // The default value will be used only when the component attaching//                           // to a node for the first time//     type: cc.SpriteFrame, // optional, default is typeof default//     serializable: true,   // optional, default is true// },// bar: {//     get () {//         return this._bar;//     },//     set (value) {//         this._bar = value;//     }// },wait: {type: cc.Node,default: null,},process_label: {type: cc.Label,default: null,},},// LIFE-CYCLE CALLBACKS:onLoad () {this.wait.active = false;this.process_label.string = "0%";},goto_roadmap : function() {/*在做场景切换的时候,如果直接切换过去,由于下一个场景一定要先加载完成它所需的资源,那么一定会卡一段时间;需要在这里加上等待界面,加入,场景加载的等待场景*/this.wait.active = true;//进度函数cc.loader.onProgress = function(completedCount, totalCount,  item ){console.log("completedCount:" + completedCount + ",totalCount:" + totalCount);var per = Math.floor(completedCount * 100 / totalCount);this.process_label.string = per+"%";}.bind(this);  //预加载场景cc.director.preloadScene("roadmap_scene", function(){cc.loader.onProgress = null;cc.director.loadScene("roadmap_scene");});},start () {},// update (dt) {},
});

3>  嫌手动关联麻烦,在场景切换中加入过渡场景,代码来加载场景的资源:

cc.loader.loadResAll("textures", function (err, assets) {         });

代码加载资源会导致setting.js文件过大,一般尽量少在代码里面加载资源;

下一篇:loader代码加载和释放资源

cocos creator入门教程(十八)—— creator_Director对象与资源加载策略相关推荐

  1. cocos creator入门教程(十七)—— creator_h5打包发布优化技巧_android环境搭建与打包发布

    android环境搭建 h5/android 打包发布 h5打包发布 1:引擎模块裁剪,减少引擎体积; 项目----项目设置----模块设置:对于游戏中没有使用到的组件,都不需要勾选.来减少引擎文件的 ...

  2. Creator3D:入门一定要会的几种资源加载

    前言 今天菜鸟整理了一些Creator3D最常见的资源加载方面的东西和大家分享一下,希望对大家有所帮助, 正文 菜鸟今天写的主要是项目中常见的动态加载图片显示和json读取. 在Creator3D中进 ...

  3. cocos creator入门教程(六)—— cc.Action使用

    Action类是动作命令,我们创建Action,然后节点运行action就能够执行Action的动作; Action分为两类: (1) 瞬时就完成的ActionInstant, (2) 要一段时间后才 ...

  4. cocos creator麻将教程系列(八)—— 达达麻将语音聊天源码分析

    达达麻将语音聊天源码分析 达达麻将版图 语音聊天 1:语音聊天只支持Native平台,iOS与android; 2: 语音聊天的音频格式为amr; 3: native平台实现了语音的录制和播放,可以移 ...

  5. Webpack入门教程十八

    91.webpack.config.js文件中entry的三种使用方式一字符串形式 /*webpack.config.js中的内容如下 */ module.exports = {entry:'./sr ...

  6. ​Cocos Creator入门实战:桌球小游戏

    本文作者:BigBear 多年游戏行业研发经验 精通Unreal.CocosCreator游戏引擎 参与过多款手游.端游项目的研发 Cocos Creator入门实战:桌球小游戏 本篇主要是希望能够通 ...

  7. Cocos Creator入门实战:桌球小游戏

    Cocos Creator入门实战:桌球小游戏 转载请保留原文链接:https://blog.csdn.net/zzx023/article/details/90035153 本篇主要是希望能够通过C ...

  8. 【Visual C++】游戏开发五十 浅墨DirectX教程十八 雪花飞扬:实现唯美的粒子系统...

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接:http://blog.csdn.net/zhmxy555/article/details/8744805 作者:毛星云(浅墨) ...

  9. ComicEnhancerPro 系列教程十八:JPG文件长度与质量

    作者:马健 邮箱:stronghorse_mj@hotmail.com 主页:http://www.comicer.com/stronghorse/ 发布:2017.07.23 教程十八:JPG文件长 ...

  10. 宏宇社:国外lead入门教程(八)申请联盟时常见的词汇与问题答案

    宏宇社:国外lead入门教程(八)申请联盟时常见的词汇与问题答案 我们在申请lead联盟的时候,一些立批的联盟会直接给你下号给你任务链接,但很多联盟是需要通过联盟经理的审批才会给你一个推广账号的.除了 ...

最新文章

  1. 买得嗨更要聊得嗨 阿里通免费电话惠战双11
  2. django学习第77天Django框架ORM
  3. 计算机组成原理——关于数据对齐存储
  4. java超时结束程序_java本机进程超时
  5. Linux监控命令之==sar
  6. python程序框架_Python 程序构架浅析
  7. Linux Curl命令实用参数
  8. TensorFlow 和keras有什么区别?
  9. Keras实现卷积神经网络
  10. 金蝶K3案例教程财务报表
  11. java里seri_全面解释Java中的serialVersionUID
  12. web前端开发师前景,96道前端面试题
  13. 如何通过Python发送邮件实现自动化测试报告?
  14. 仿雷速体育app踢足球tab
  15. 最新xmind2022版思维导图如何使用详解教程
  16. 前端效果之“拉开窗帘”
  17. MATLAB数字图像处理系统——边缘检测
  18. javascript 中的window, document, screen都有什么区别?
  19. 整合篇:零基础学习与使用ElasticSearch
  20. C 碎片八 结构体amp;枚举amp;联合

热门文章

  1. linux初级:用useradd SB2,来建立新账户时,显示 bash:useradd:command not found的解决方法
  2. 如何查看论文被收录的情况?
  3. scratch3.0 整体页面介绍
  4. ISO50001认证辅导,ISO50001能源管理体系认证至少符合以下条件
  5. 关于WIN11使用SecoClient接收返回码超时问题
  6. 阶乘的传统流程图 c语言,C语言算法与流程图.ppt
  7. 苹果电脑有哪些很优秀的录屏软件呢?
  8. Visio帮你轻松画出3D效果示意图
  9. ax200 兼容性问题 老路由器_WiFi6来了!但我们究竟应不应该换哥新的路由器呢
  10. 《LabVIEW FPGA开发宝典》第9章:利用树莓派Linux RT+FPGA PCIe实现国产化RIO