Sign in to follow this  
John Does

Using the while statement instead of the Babylon.js built-in animation

Recommended Posts

I have no particular problem,but I was wondering...


Wouldnt I be able to use the while statement instead of using the built-in animation.


And if the while statement were to work, wouldnt be faster than the built-in animation?

Share this post

Link to post
Share on other sites

Hi John,


I assume you mean that this code will work faster?

while(running) {    scene.render();}

There are many reasons why this would never work, mainly due to JS's engine architecture. The same reasons why requestAnimationFrame was introduced to browsers.

If this is what you mean, I can try explaining shortly why it won't work.

Share this post

Link to post
Share on other sites


I agree wih Raanan.


The global architecture is asynchronous and event driven.

This means that things are triggered according to some event spawnings : the next frame must be displayed, the user moved the mouse, this image file is downloaded, or internal ones : these physics were computed, this cam collision computation is done, etc.

And each thing try be computed as fast as possible in order not to delay the others that will happen in turn. If it lasts too much, the others will only when it's finished anyway. Imagine if it never finishes ... the others will never start. The engine is then stopped, doing endlessly only one thing.


If you inject a while loop in this big architecture, you may add an infinite loop into this big evented construction, it is to say something that never ends, or that lasts too much, and prevents all the other process to start in time.

Share this post

Link to post
Share on other sites

Hi JD and other friends.  ( a playground to play with )  :)

Personally, I, also, cannot see why lines 31-36 animator doesn't work.  Seems it should.  But I know very little about the JS "threading model" or whatever it's called.

The lines 40-44 animator works fine once activated.  (and de-activate 31-36 as well)

JD, you ask good questions, and welcome to the forum.

PS: I once did an animation using a switch/case system (with delays between phases).  The animated object keeps track of which phase of the animation it is in/at. .  Not very good programming on my part, but it got the job done, and it didn't use any Babylon.Animation. This demo, and two similar ones... are listed in our Babylon Primer.   Party on, guys!

Share this post

Link to post
Share on other sites

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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.