常用接口 1: getWinSize: 适配后的逻辑大小; 2: getWinSizeInPixels: 获取窗口的像素大小; 3: getScene: 获取当前的逻辑场景,场景对象下面是Canvas; 4: setdisplayStats: 是否显示左下角FPS信息; 5: getCollisionManager: 获取碰撞检测管理对象; 6: getPhysicsManager :获取物理引擎管理对象; 7:loadScene(scene_name):加载场景,场景的名字,系统会加载对应的场景 8:preloadScene(scene_name):预加载场景
资源加载策略
1: h5资源加载的过程: (1)从服务器上下载来来资源,并把资源加载到内存中,所以你在做h5游戏,你要把你当前游戏中要用到的资源先加载下来,否者的话,你在运行的时候去加载就来不及了(h5卡住); 2:三种资源加载策略: 1>: h5的小游戏:采用全部提前绑定好所有的资源。编写预加载脚本preload.Js, 将要加载的资源手动关联到第一个启动的场景上面,一次性预加载所有; 2>: 添加等待界面,预加载下一个场景,然后再进行切换,提前关联好下一个场景要的资源,每一个需要加载资源的场景都应该挂载一个preload.Js脚本区关联资源; cc.loader.onProgress = function ( completedCount,totalCount,item ){ console.log("completedCount:" + completedCount + ",totalCount:" + totalCount ); }; 3> 嫌手动关联麻烦,在场景切换中加入过渡场景,代码来加载场景的资源: cc.loader.loadResAll("textures",function (err,assets) { }); 代码加载资源会导致setting.Js文件过大,一般尽量少在代码里面加载资源;
//preload.Js 挂载资源的脚本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,default is true // visible: true,default is true // displayname: ‘Foo‘,// optional // Readonly: false,default is false // }, // ... img_array: { type: cc.SpriteFrame,default: [],},atlas_array: { default: [],type: cc.SpriteAtlas,sound_array: { default: [],url: cc.AudioClip,prefab_array: { default: [],type: cc.Prefab,// use this for initialization onLoad: function () { },// called every frame,uncomment this function to activate update callback // update: function (dt) { // },});
//home_scene.Js 预加载下个场景资源的处理脚本cc.Class({ extends: cc.Component, // ... wait: { type: cc.Node,default: null,progress_label: { type: cc.Label,// use this for initialization onLoad: function () { this.wait.active = false; this.progress_label.string = "0%"; },goto_roadmap: function() { // 你在做场景切换的时候,如果你直接切换过去, // 由于下一个场景一定要先加载完它所需要的资源,那么一定会卡住一段时间; // 会在这里加上我们的等待界面,加入,场景加载的等待场景; this.wait.active = true; cc.loader.onProgress = function(completedCount,item){ console.log("completedCount:" + completedCount + ",totalCount:" + totalCount); var per = Math.floor(completedCount * 100 / totalCount); this.progress_label.string = per + "%"; }.bind(this); // 预加载 cc.director.preloadScene("roadmap_scene",function() { cc.loader.onProgress = null; cc.director.loadScene("roadmap_scene"); }); // end },});总结
以上是内存溢出为你收集整理的cocos creator基础-(二十四)cc.Director与资源加载策略全部内容,希望文章能够帮你解决cocos creator基础-(二十四)cc.Director与资源加载策略所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)