Skip to content

jeromeetienne/threex.loop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

threex.loop

threex.loop is a threex game extension for three.js. It provides loops for your game. You can easily add your own functions in/from the loop. You can create different kind of loops: Rendering loop which are updated with requestAnimationFrame, Physics loop which are regurlarly updated based on setTimeout with a rate you choose and the plain loop is up to you to update manually.

Show Don't Tell

A Screenshot

screenshot

How To Install It

You can install it via script tag

<script src='threex.loop.js'></script>

Or you can install with bower, as you wish.

bower install threex.loop

How To Use Basic Loop ?

You create the basic loop like this

var loop    = new THREEx.Loop()

Then you add functions to this loop. Then those functions will then be updated in the same order you added them.

function function1(delta){
    console.log('function1')
})
loop.add(function1)

If you need to remove the function from the loop, loop.remove(function1).Then you update the loop with a delay in second. It will call all the functions added to the loop.

loop.update(60/1000)

How To Use A Rendering Loop ?

First you create the loop

var loop    = new THREEx.RenderingLoop()

Here you can add/remove functions to the loop the same way you did it for the basic loop. Those functions will be updated based on requestAnimationFrame. So it depends on your FPS or if the page is visible by the user.

loop.start()

It is that simple. Then you can stop it with loop.stop() or test if it is running with loop.isRunning().

How To Use A Physics Loop ?

First you create the loop. It will regurlarly updated based on setTimeout with a rate you choose. Let's update our loop 10 time per second

var loop    = new THREEx.PhysicsLoop(10)

Here you can add/remove functions to the loop the same way you did it for the basic loop. You can change the update rate by changing loop.rate = 15

loop.start()

It is that simple. Then you can stop it with loop.stop() or test if it is running with loop.isRunning().

About

provides rendering and physics loop for your three.js game

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published