Animation Using the Render Loop
Animation Using the Render Loop
Babylon.js allows you to change an object's properties immediately before or after a frame is rendered. This is an alternative way of producing animation in a scene. This type of animation lets you control everything on each frame of the animation (each tick). The code computed at run time must be located in this function:
scene.onBeforeRenderObservable.add(() => { //Your code here});The functions added to onBeforeRenderObservable() run before every frame (usually ~60 times per second), so animation is created by making small changes to object properties very quickly.
A simple demonstration of complex animation can be found in the playground here:
Render Loop Animation ExampleThis function can be very useful for complex animations, such as games, where characters have to move depending on many parameters.
Don’t hesitate to combine all those types of animations. If done well, it’s very powerful.
Don't forget to visit our API documentation in order to learn more about the Babylon.js Animation and Babylon.js Animatable classes.