src/mainloop.js
function() {
        if (!started) {
            // Since the application doesn't start running immediately, track
            // whether this function was called and use that to keep it from
            // starting the main loop multiple times.
            started = true;

            // In the main loop, draw() is called after update(), so if we
            // entered the main loop immediately, we would never render the
            // initial state before any updates occur. Instead, we run one
            // frame where all we do is draw, and then start the main loop with
            // the next frame.
            rafHandle = requestAnimationFrame(function(timestamp) {
                // Render the initial state before any updates occur.
                draw(1);

                // The application isn't considered "running" until the
                // application starts drawing.
                running = true;

                // Reset variables that are used for tracking time so that we
                // don't simulate time passed while the application was paused.
                lastFrameTimeMs = timestamp;
                lastFpsUpdate = timestamp;
                framesSinceLastFpsUpdate = 0;

                // Start the main loop.
                rafHandle = requestAnimationFrame(animate);
            });
        }
        return this;
    }
function() {
        if (!started) {
            // Since the application doesn't start running immediately, track
            // whether this function was called and use that to keep it from
            // starting the main loop multiple times.
            started = true;

            // In the main loop, draw() is called after update(), so if we
            // entered the main loop immediately, we would never render the
            // initial state before any updates occur. Instead, we run one
            // frame where all we do is draw, and then start the main loop with
            // the next frame.
            rafHandle = requestAnimationFrame(function(timestamp) {
                // Render the initial state before any updates occur.
                draw(1);

                // The application isn't considered "running" until the
                // application starts drawing.
                running = true;

                // Reset variables that are used for tracking time so that we
                // don't simulate time passed while the application was paused.
                lastFrameTimeMs = timestamp;
                lastFpsUpdate = timestamp;
                framesSinceLastFpsUpdate = 0;

                // Start the main loop.
                rafHandle = requestAnimationFrame(animate);
            });
        }
        return this;
    }
function ( ) { if ( ! started ) { // Since the application doesn't start running immediately, track // whether this function was called and use that to keep it from // starting the main loop multiple times. started = true ; // In the main loop, draw() is called after update(), so if we // entered the main loop immediately, we would never render the // initial state before any updates occur. Instead, we run one // frame where all we do is draw, and then start the main loop with // the next frame. rafHandle = requestAnimationFrame ( function ( timestamp ) { // Render the initial state before any updates occur. draw ( 1 ) ; // The application isn't considered "running" until the // application starts drawing. running = true ; // Reset variables that are used for tracking time so that we // don't simulate time passed while the application was paused. lastFrameTimeMs = timestamp ; lastFpsUpdate = timestamp ; framesSinceLastFpsUpdate = 0 ; // Start the main loop. rafHandle = requestAnimationFrame ( animate ) ; } ) ; } return this ; }
Starts the main loop.

Note that the application is not considered "running" immediately after
this function returns; rather, it is considered "running" after the
application draws its first frame. The distinction is that event
handlers should remain paused until the application is running, even
after `MainLoop.start()` is called. Check `MainLoop.isRunning()` for the
current status. To act after the application starts, register a callback
with requestAnimationFrame() after calling this function and execute the
action in that callback. It is safe to call `MainLoop.start()` multiple
times even before the application starts running and without calling
`MainLoop.stop()` in between, although there is no reason to do this;
the main loop will only start if it is not already started.

See also `MainLoop.stop()`.
Starts the main loop .