Animation loop in PhET

34 views
Skip to first unread message

Alberto Corbi

unread,
May 31, 2021, 11:36:09 AM5/31/21
to Developing Interactive Simulations in HTML5
Dear PhET community, 

Could you please explain how is the refresh/animation loop handled in Scenery? Is there a function or method called periodically on every Node object?

Kindest regards, 
Alberto 

cmalley

unread,
Jun 1, 2021, 12:31:23 PM6/1/21
to Developing Interactive Simulations in HTML5
Hi Alberto,

The animation loop (and many other things) are handled in Sim.js, https://github.com/phetsims/joist/blob/master/js/Sim.js.  A simulation's main.js file is where Sim is instantiated and started  by calling the start method.  For example, see https://github.com/phetsims/natural-selection/blob/master/js/natural-selection-main.js.

Sim sets up the animation loop in method runAnimationLoop.  This results in  stepSimulationAction being executed on each animation frame - have a look there to see what is actually done on each step.

I hope this helps!

Chris Malley
PixelZoom, Inc.

Alberto Corbi

unread,
Jun 3, 2021, 9:12:42 AM6/3/21
to Developing Interactive Simulations in HTML5
Thanks Cris.
Reply all
Reply to author
Forward
0 new messages