s4m_ur4i Posted October 5, 2018 Share Posted October 5, 2018 Quote When Sprite's are created they are added to two lists within the Scene - the Display List and the Update List. Under 3.12 when a Scene was shut down it would emit a shutdown event, which Sprites listened out for. When they received it, they would destroy themselves. After profiling and testing this process has changed slightly. Game Object's no longer listen for the Scene shutdown event. Instead, the Display List and Update List will iterate their children and call destroy on them in turn. If being destroyed by a Scene in this way, the child will skip several expensive operations in its destroy function. More importantly, in busy Scenes you no longer need thousands of event listeners registered. The result is that changing Scene is now up to 100% faster than before. You need not change your code to benefit from this, however, if you were relying on custom Game Objects listening for the Scene shutdown event natively, then this is no longer the case and you'll have to manually add that listener to your classes. 6 As I understand there was an optimization to how things are erased from old scenes (not active scenes). Considering the last sentence, I have to optimize my code. But I am not really aware of how. The shutdown event has to be called manually on custom GameObjects. But I only guess that's how to do: class Parrot extends Phaser.GameObjects.Sprite { constructor(config) { super(config.scene, config.x * SCALE, config.y * SCALE, 'animals', 15); this.scene.events.on('shutdown', this.destroy(), this); //<- is it just that? } } For any explanation I would be grateful, thanks in advance! Link to comment Share on other sites More sharing options...
samme Posted October 6, 2018 Share Posted October 6, 2018 As long as the parrots are on the scene's update list or display list already, they will still get destroyed when you stop the scene. There's nothing extra you have to do. s4m_ur4i 1 Link to comment Share on other sites More sharing options...
s4m_ur4i Posted October 6, 2018 Author Share Posted October 6, 2018 Thanks a lot. Link to comment Share on other sites More sharing options...
f0obar Posted May 24, 2019 Share Posted May 24, 2019 Also, keep in mind that in order to pass a function as argument to another function, you (usually*) must not invoke it. When you wrote this.scene.events.on('shutdown', this.destroy(), this); you basically called this.destroy() and gave this.scene.events.on whatever this.destroy() returned after being called. That's like saying 'I want to add numbers 1 and 3 therefore I'm applying the operation "1+3" between them'. That's not correct since '1+3' is not an operation, but a result (4, to be precise). What you really wanted to say was 'I want to add numbers 1 and 3 therefore I'm applying the operation "+" between them'; therefore, analogically, the code above would simply change to this.scene.events.on('shutdown', this.destroy, this); *I said usually because it sometimes makes sense to invoke a function in another function's argument list when that function returns another function, i.e. applyOperationBetweenNumbers(getOperationByName('plus'), 1, 3) Link to comment Share on other sites More sharing options...
Recommended Posts