Skip to content
cjcliffe edited this page Feb 25, 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 recieve the parameters _loopCallback( timer, gl )_ for a CubicVR.Timer and the WebGL Context. *doClear* - Whether or not to call gl.clear( DEPTH_BUFFER | COLOR_BUFFER ) before each frame. **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 )

Purpose:
Set the timer to paused or unpaused state.
Parameters:
state - true to pause, false to unpause.
Returns:
none.


getPaused()

Purpose:
Get the timer to paused state.
Returns:
true if paused, false if not.


setTimerSeconds( timerSeconds )

Purpose:
Set the timer to a specific time, in Seconds.
Parameters:
timerSeconds - The new time in Seconds.
Returns:
none.


getTimerSeconds()

Purpose:
Get the current time position from the timer in Seconds.
Returns:
Timer posision in Seconds.


resetTimer()

Purpose:
Reset the timer to 0.
Returns:
none.


Clone this wiki locally