Class jaws.GameLoop
A classic game loop forever looping calls to update() / draw() with given framerate. "Field Summary" contains options for the GameLoop()-constructor.
- Defined in: game_loop.js
Constructor Attributes | Constructor Name and Description |
---|---|
jaws.GameLoop(game_object, options, game_state_setup_options)
|
Field Attributes | Field Name and Description |
---|---|
the real fps (as opposed to the target fps), smoothed out with a moving average
|
|
duration in ms between the last 2 ticks (often called dt)
|
|
total amount of ticks since game loops start
|
Method Summary
Method Attributes | Method Name and Description |
---|---|
loop()
The core of the game loop.
|
|
pause()
Pause the game loop.
|
|
runtime()
returns how game_loop has been active in milliseconds
does currently not factor in pause-time
|
|
start()
Start the game loop by calling setup() once and then loop update()/draw() forever with given FPS
|
|
stop()
Stop the game loop
|
|
unpause()
unpause the game loop
|
Class Detail
jaws.GameLoop(game_object, options, game_state_setup_options)
game = {} draw: function() { ... your stuff executed every 30 FPS ... } } game_loop = new jaws.GameLoop(game, {fps: 30}) game_loop.start() // You can also use the shortcut jaws.start(), it will: // 1) Load all assets with jaws.assets.loadAll() // 2) Create a GameLoop() and start it jaws.start(MyGameState, {fps: 30})
- Parameters:
- game_object
- options
- game_state_setup_options
Field Detail
{int}
fps
the real fps (as opposed to the target fps), smoothed out with a moving average
{int}
tick_duration
duration in ms between the last 2 ticks (often called dt)
{int}
ticks
total amount of ticks since game loops start
Method Detail
-
loop()The core of the game loop. Calculate a mean FPS and call update()/draw() if game loop is not paused
-
pause()Pause the game loop. loop() will still get called but not update() / draw()
-
runtime()returns how game_loop has been active in milliseconds does currently not factor in pause-time
-
start()Start the game loop by calling setup() once and then loop update()/draw() forever with given FPS
-
stop()Stop the game loop
-
unpause()unpause the game loop