I have this idea, can I call a method when the game is loaded to cache all the resources of the entire game, and then use the Preload() method in the specific Scene to get the resources that I previously cached In this way, I can ensure that each Scene is coherent and won’t waste time loading resources.
The Texture/Audio Managers already cache everything. If you use preload in your first scene, you can use all those resources in any scene.
The ‘add’ method is useful if you don’t want to use preload, so if you have your own loader, or created a resource dynamically.
I want to cache some resources in the first Scene to ensure the smooth playback of the following Scenes, so I implement a method to store resources by myself. Is this method feasible?
I don’t know how often I am going to have to repeat myself
Preload everything you want in the first Scene. Then they are cached. Why would you want to make another cache?
Any following scene will not have to load anything, because the first scene already did that.
Then load them whenever you want. Do some in the first. some in the second. Whatever. But you don’t need to make your own cache manager. Whenever you load something, you can reference the cache by its key.
The TextureManager is an EventEmitter that fires events, presumably when textures are loaded and unloaded. Also, there are methods for removing individual textures by name. I can’t tell how complete the capabilities are (e.g., the docs fail to even enumerate the event names that the TextureManager can emit), but there may be enough of a foundation for custom eviction logic.