I created a game in three.js, which exists from 3 scenes GameScene , MenuScene and HighScoreScene . The user can switch between these scenes. When a player changes the scene, for example. from MenuScene to HighScoreScene I am trying to clear resources from an old scene.
But clearing the resources doesn't seem to work. So, here is my code that runs when the user switches between scenes:
So, in the old scene, I have an animation loop:
function cancelAnimation() { cancelAnimationFrame(animationFrameId);
So, when switching the scene, I turned off all clicks, and I call cancelAnimation .
Since I save this code for each scene in an object like var menuScene = new MenuScene() , I also do this menuScene = undefined when switching the scene.
I also pass the same instance var renderer = new THREE.WebGLRenderer(); for the scene.
All this does not seem to help the game more slowly.
What is the right way to switch between these scenes and clear resources? What am I doing wrong here?
source share