What’s the difference between these two approaches? In both cases I call calcBeforeRender()
before scene will be rendered. So what the difference?
1:
scene.registerBeforeRender( () => {
calcBeforeRender();
} );
engine.runRenderLoop( () => {
scene.render();
}
2:
engine.runRenderLoop( () => {
calcBeforeRender();
scene.render();
}
Normally a game can have one engine and multiple scenes. If you use registerBeforeRender you don’t have to check if sceneN is active in your runRenderLoop:
if(scene1.isActive) { … }
if(scene2.isActive) { … }
…
So you can execute instructions that are scene-specific and others that are global (for all scenes). With only one scene, there is no difference. Additionally it could be that you don’t own the engine/runRenderLoop like in Playground.
3 Likes