Jump to content

redfine runRenderLoop and multiple scenes


amorgan
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • 6 months later...

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...