Where is the game loop?

i am really new to babylong, and i finally set up my environment in typescript with webpack, however i know so far we run the game wit the function: engine.runRenderLoop();

my questions are:
is that the game loop?
do we have a delta for the game loop?
i suppose the updates of the game comes before rendering the objects but inside runRenderLoop function?
it is possible to create my own game loop?

any link to reply to above questions are welcome.

Welcome abroad! Going question by question:

  1. is that the game loop?

Yes, you can consider it as a game loop.

  1. do we have a delta for the game loop?

You can use engine.getDeltaTime: Engine | Babylon.js Documentation (babylonjs.com)

  1. i suppose the updates of the game comes before rendering the objects but inside runRenderLoop function?

As zhangyahan mentioned, you could use the onBeforeRender observable, it runs before each scene render. Or you could update on the renderLoop itself. We don’t enforce a single method, what works for you is fine :slight_smile:

  1. it is possible to create my own game loop?

Yes it is! runRenderLoop is just a convenience function, but you can create your render loop logic yourself. Just call scene.render whenever you want to render a scene.

1 Like

thanks for the replies, about 4 question, i am just calling scene.render once and just with that the loop seems to start and work, is there are an impact if i use scene.render(); multiple times?

You need to call scene.render in your loop. There is no impact. scene.render() draws your scene. If you only call it once, it will draw the scene once, but then everything will freeze.

1 Like