mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 16:52:43 +08:00
Improve persistRootNode transition to new scene (#3018)
This commit is contained in:
+13
-21
@@ -414,19 +414,27 @@ cc.Director.prototype = {
|
||||
scene._load(); // ensure scene initialized
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('InitScene');
|
||||
|
||||
// detach persist nodes
|
||||
// Re-attach or replace persist nodes
|
||||
CC_BUILD && CC_DEBUG && console.time('AttachPersist');
|
||||
var persistNodeList = Object.keys(game._persistRootNodes).map(function (x) {
|
||||
return game._persistRootNodes[x];
|
||||
});
|
||||
for (let i = 0; i < persistNodeList.length; i++) {
|
||||
let node = persistNodeList[i];
|
||||
game._ignoreRemovePersistNode = node;
|
||||
node.parent = null;
|
||||
game._ignoreRemovePersistNode = null;
|
||||
var existNode = scene.getChildByUuid(node.uuid);
|
||||
if (existNode) {
|
||||
// scene also contains the persist node, select the old one
|
||||
var index = existNode.getSiblingIndex();
|
||||
existNode._destroyImmediate();
|
||||
scene.insertChild(node, index);
|
||||
}
|
||||
else {
|
||||
node.parent = scene;
|
||||
}
|
||||
}
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('AttachPersist');
|
||||
|
||||
var oldScene = this._scene;
|
||||
|
||||
if (!CC_EDITOR) {
|
||||
// auto release assets
|
||||
CC_BUILD && CC_DEBUG && console.time('AutoRelease');
|
||||
@@ -455,22 +463,6 @@ cc.Director.prototype = {
|
||||
// Run an Entity Scene
|
||||
this._scene = scene;
|
||||
|
||||
// Re-attach or replace persist nodes
|
||||
CC_BUILD && CC_DEBUG && console.time('AttachPersist');
|
||||
for (let i = 0; i < persistNodeList.length; i++) {
|
||||
let node = persistNodeList[i];
|
||||
var existNode = scene.getChildByUuid(node.uuid);
|
||||
if (existNode) {
|
||||
// scene also contains the persist node, select the old one
|
||||
var index = existNode.getSiblingIndex();
|
||||
existNode._destroyImmediate();
|
||||
scene.insertChild(node, index);
|
||||
}
|
||||
else {
|
||||
node.parent = scene;
|
||||
}
|
||||
}
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('AttachPersist');
|
||||
CC_BUILD && CC_DEBUG && console.time('Activate');
|
||||
scene._activate();
|
||||
CC_BUILD && CC_DEBUG && console.timeEnd('Activate');
|
||||
|
||||
+4
-13
@@ -114,7 +114,6 @@ var game = {
|
||||
RENDER_TYPE_OPENGL: 2,
|
||||
|
||||
_persistRootNodes: {},
|
||||
_ignoreRemovePersistNode: null,
|
||||
|
||||
// states
|
||||
_paused: true,//whether the game is paused
|
||||
@@ -436,12 +435,6 @@ var game = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* !#en cc.game is the singleton object for game related functions.
|
||||
* !#zh cc.game 是 Game 的实例,用来驱动整个游戏。
|
||||
* @class Game
|
||||
*/
|
||||
|
||||
/**
|
||||
* !#en Run game with configuration object and onStart function.
|
||||
* !#zh 运行游戏,并且指定引擎配置和 onStart 的回调。
|
||||
@@ -499,12 +492,10 @@ var game = {
|
||||
* @param {Node} node - The node to be removed from persistent node list
|
||||
*/
|
||||
removePersistRootNode: function (node) {
|
||||
if (node !== this._ignoreRemovePersistNode) {
|
||||
var id = node.uuid || '';
|
||||
if (node === this._persistRootNodes[id]) {
|
||||
delete this._persistRootNodes[id];
|
||||
node._persistNode = false;
|
||||
}
|
||||
var id = node.uuid || '';
|
||||
if (node === this._persistRootNodes[id]) {
|
||||
delete this._persistRootNodes[id];
|
||||
node._persistNode = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user