amorgan Posted December 15, 2014 Share Posted December 15, 2014 Hello, my question is what is the correct way to switch between scenes? I saw another topic that was to just have the renderLoop function be:engine.runRenderLoop(function () { scene[activeScene].render();});But I was wondering, can I redefine the renderLoop? If I do:engine.stopRenderLoop();engine.runRenderLoop(function () { scene[activeScene].renderLoop();});scene[activeScene].renderLoop = function () { //do stuff specific to activeScene this.render();}When I try to do this, the first scene I load displays and behaves correctly (or whatever I set activeScene to). When I try to set scene[0].renderLoop as my renderLoop function and then switch to scene[1].renderLoop, the second scence, scene[1], isn't visible, but FPS is still being calcuated and it is cycling through the correct renderLoop and all of the scene information exists. Note: scene[0] and scene[1] are just examples, it could be switched and still behave the same. Is there something extra I need to do before calling engine.runRenderLoop() again? or can I even do this? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 15, 2014 Share Posted December 15, 2014 I did not get why you need to do this. Can you create a playground to highlight your problem? Quote Link to comment Share on other sites More sharing options...
amorgan Posted December 15, 2014 Author Share Posted December 15, 2014 The reason behind it would be to have a start Scene that is in the background with DOM elementes where the user can select to start a game, sign in, etc. Then I have a game scene, which contains the scene that is the actual game. The reason I was seperating them is because I can load them seperately using the Asset Manager. As in, I can load the start scene first and have it's own renderLoop and continue loading the game scene in preperation. In addition to keeping them in separate objects. The game scene will have separate logic that is needed for the game, but not the start scene. I didn't createa playground at first because I wasn't sure at first how to create this example, but I was able to hack it out and it behaved as expected. So I looked back at my code and figured out I was destroying a DOM element (the renderCanvas), which was my problem. This method actually works nicely. Click the FPS label on the upper right of the scene to toggle back and forth: http://www.babylonjs-playground.com/#1B3R9A Thanks for you time DeltaKosh! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 15, 2014 Share Posted December 15, 2014 Maybe?engine.runRenderLoop(function () { scene[activeScene].render(); if (activeScene === 99){ // do extra stuff }}); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 15, 2014 Share Posted December 15, 2014 This is the magic of playground Your solution sounds great to me! amorgan 1 Quote Link to comment Share on other sites More sharing options...
amorgan Posted December 15, 2014 Author Share Posted December 15, 2014 i wanted to avoid extra logic in the renderLoop since this is one of the higher intensive loops. The playground I posted works the way I wanted. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 28, 2015 Share Posted June 28, 2015 I was doing research on multi scenes and testing this scene, which worked before, no longer works in 2.2. Is a bug? PLaygroundhttp://www.babylonjs-playground.com/#1B3R9A error:Cannot read property 'depthMask' of null Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 29, 2015 Share Posted June 29, 2015 Works for me Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 29, 2015 Share Posted June 29, 2015 This seems random. try to run several times and the bug happens. 1) Click run2) click bull fps3) click run4) click bull fps => bug Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted June 30, 2015 Share Posted June 30, 2015 This is because you registered the render loop twice:http://www.babylonjs-playground.com/#1B3R9A#2 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted June 30, 2015 Share Posted June 30, 2015 No this is not me to do that. I tested this code writing amorgan. Thank you for clarification DK Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.