Merge pull request #865 from jareguo/v1.1

preload scene in runtime platform
This commit is contained in:
Wang Nan
2016-07-04 10:33:51 +08:00
committed by GitHub
3 changed files with 35 additions and 16 deletions
+1
View File
@@ -10,3 +10,4 @@ node_modules
/package
/tools/jsdoc_toolkit/jsdoc_toolkit-2.4.0
/.project
npm-debug.log
+17 -8
View File
@@ -691,13 +691,13 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
for (var i = 0; i < scenes.length; i++) {
var info = scenes[i];
if (info.url.endsWith(key)) {
return info.uuid;
return info;
}
}
}
else if (typeof key === 'number') {
if (0 <= key && key < scenes.length) {
return scenes[key].uuid;
return scenes[key];
}
else {
cc.error('loadScene: The scene index to load (%s) is out of range.', key);
@@ -723,11 +723,20 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
cc.error('loadScene: Failed to load scene "%s" because "%s" is already loading', sceneName, this._loadingScene);
return false;
}
var uuid = this._getSceneUuid(sceneName);
if (uuid) {
var info = this._getSceneUuid(sceneName);
if (info) {
var uuid = info.uuid;
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
this._loadingScene = sceneName;
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
if (CC_JSB && cc.runtime) {
var self = this;
cc.LoaderLayer.preload([cc.path.basename(info.url) + '_' + info.uuid], function () {
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
});
}
else {
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
}
return true;
}
else {
@@ -752,10 +761,10 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
* @param {Error} onLoaded.error - null or the error object.
*/
preloadScene: function (sceneName, onLoaded) {
var uuid = this._getSceneUuid(sceneName);
if (uuid) {
var info = this._getSceneUuid(sceneName);
if (info) {
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
cc.loader.load({ id: uuid, type: 'uuid' }, function (error, asset) {
cc.loader.load({ id: info.uuid, type: 'uuid' }, function (error, asset) {
if (error) {
cc.error('Failed to preload "%s", %s', sceneName, error.message);
}
+17 -8
View File
@@ -223,13 +223,13 @@ cc.js.mixin(cc.director, {
for (var i = 0; i < scenes.length; i++) {
var info = scenes[i];
if (info.url.endsWith(key)) {
return info.uuid;
return info;
}
}
}
else if (typeof key === 'number') {
if (0 <= key && key < scenes.length) {
return scenes[key].uuid;
return scenes[key];
}
else {
cc.error('loadScene: The scene index to load (%s) is out of range.', key);
@@ -254,11 +254,20 @@ cc.js.mixin(cc.director, {
cc.error('loadScene: Failed to load scene "%s" because "%s" is already loading', sceneName, this._loadingScene);
return false;
}
var uuid = this._getSceneUuid(sceneName);
if (uuid) {
var info = this._getSceneUuid(sceneName);
if (info) {
var uuid = info.uuid;
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
this._loadingScene = sceneName;
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
if (CC_JSB && cc.runtime) {
var self = this;
cc.LoaderLayer.preload([cc.path.basename(info.url) + '_' + info.uuid], function () {
self._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
});
}
else {
this._loadSceneByUuid(uuid, onLaunched, _onUnloaded);
}
return true;
}
else {
@@ -268,10 +277,10 @@ cc.js.mixin(cc.director, {
},
preloadScene: function (sceneName, onLoaded) {
var uuid = this._getSceneUuid(sceneName);
if (uuid) {
var info = this._getSceneUuid(sceneName);
if (info) {
this.emit(cc.Director.EVENT_BEFORE_SCENE_LOADING, sceneName);
cc.loader.load({ id: uuid, type: 'uuid' }, function (error, asset) {
cc.loader.load({ id: info.uuid, type: 'uuid' }, function (error, asset) {
if (error) {
cc.error('Failed to preload "%s", %s', sceneName, error.message);
}