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.
- examples/basic.html [view source] : It shows this feature, and that one which is coded like that.
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
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)
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()
.
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()
.