I'm new to three.js and I'm trying out a very basic shooter. The user should shoot a colored crate (box). When he does so, the crate disappears and another random crate appears, and so on.
if (intersects.length > 0) {
intersects[0].object.material.color.setHex(Math.random() * 0xffffff);
scene.remove(object);
create_cube();
animate();
...
On landing, it works very smoothly. No lag at all. But the more boxes I shoot, the more the game begins to lag.
Am I doing something wrong in terms of memory allocation or garbage collection?
Here's a JSfiddle: https://jsfiddle.net/k0s2nmru/
(while my code works fine as a separate page, it doesn't seem to work when placed inside JSfiddle)
Update:
I've added stats that come with three.js. They keep giving me pretty good frames per second (up to 150 and more), even though the game starts to lag. Maybe I didn't implement it the right way?