I’m trying to create scene loading (elements under ‘sceneContent’ while keep some persistent elements (elements under “static content”, a ui for for example). My current way is to load the new root element and then move the static content into this new structure, before destroying the old “Root”.
Is this a good solution or are there simpler / better ways of doing that?
Thanks for any heads up!
SceneManager.prototype.loadScene = function (sceneName) {
if(sceneName != this.currentScene){
this.currentScene = sceneName;
// Get a reference to the scene's root object
var oldHierarchy = this.app.root.findByName ('Root');
var staticContent = oldHierarchy.findByName('staticContent');
// Get the path to the scene
var scene = this.app.scenes.find(sceneName);
// Load the scenes entity hierarchy
this.app.scenes.loadScene(scene.url, function (err, scene) {
oldHierarchy.removeChild(staticContent);
oldHierarchy.destroy();
var newHierarchy = this.app.root.findByName ('Root');
newHierarchy.addChild(staticContent);
pc.ComponentSystem.initialize(this.app.root.findByName ('sceneContent'));
pc.ComponentSystem.postInitialize(this.app.root.findByName ('sceneContent'));
});
}
};