Loops & 3D Animation
You don't need to write animate()
function like you do in Three.js. The problem is that bigger you app become, the bigger your animate()
function is.
Here comes WHS.Loop
class. With just a few lines of code you can your own mini-animate() function:
const app = new WHS.App([
// ...
]);
new WHS.Loop(() => {
box.rotation.y += 0.02;
}).start(app);
And you can make loop temporary like that:
const loop = new WHS.Loop((clock) => {
// ...
if (clock.getElapsedTime() > 5) loop.stop(app);
});
loop.start(app);
This loop will be destroyed after 5 seconds.
Updated almost 8 years ago