Skip to content
cjcliffe edited this page Oct 15, 2011 · 5 revisions

CubicVR.MainLoop

The MainLoop provides a simple way to wrap your main drawing loop.

It also provides a CubicVR.Timer as well as the WebGL Context as two parameters to your callback respectively. MainLoop will use the window.*requestAnimationFrame() methods to manage framerate where available and fallback to setInterval() otherwise.

Constructor:

MainLoop( loopCallback, doClear )

Parameters:

  • loopCallback : Your main draw loop function, it will receive the parameters loopCallback( timer, gl ) for a CubicVR.Timer and the WebGL Context.
  • doClear (optional) : Whether or not to call gl.clear( DEPTH_BUFFER | COLOR_BUFFER ) before each frame, default: true.

Returns:

If called with new MainLoop(..) will return a MainLoop instance, none if used as singleton.

Typical Usage:

var myloop = new CubicVR.MainLoop(function (timer,gl) {  
   // ...  
});

or

CubicVR.MainLoop(function (timer,gl) {  
   // ...
});

Methods:

setPaused( state )

Set the Timer to paused or unpaused state.

Parameters:

  • state : true to pause, false to unpause.

Returns:

none

getPaused()

Get the Timer paused state.

Returns:

true if paused, false if not.

setTimerSeconds( timerSeconds )

Set the Timer to a specific time, in Seconds.

Parameters:

  • timerSeconds : The new time in Seconds.

Returns:

none

getTimerSeconds()

Get the current time position from the timer in Seconds.

Returns:

Timer position in Seconds.

resetTimer()

Reset the Timer to 0.

Returns:

none

Clone this wiki locally