Jump to content

Preloading images - use preload state or preload function?


jdx2015
 Share

Recommended Posts

Hi Everyone,

 

I'm new to Phaser and I have a quick question about preloading game images. 

 

In terms of memory management, is it better to use a "preload.js" state to load all images up front, or use the "preload" function in each individual state to load only the images that are needed?

 

Also, are the images removed from memory when the state changes, or do I need to make a shutdown function to explicitly destroy the images created in that state?

Link to comment
Share on other sites

Having a preload state that does all the loading is nice because you basically front-load the wait time that a user has to face right at the beginning. I think it's better than having to having a loading screen for every state.

 

However, it also depends on how big your game is. If you end up with a big game with 10 levels each with 1MB per level for resources, it might make sense to break it out into the individual preload methods, rather than force a user to wait for the first 10MB to download before they get to interact with the game.

 

In terms of memory management? I guess it depends on what you are trying to achieve. Having the state of the entire game in memory will make the game fast to load between levels/states. However, it will end up taking a large  portion of your available memory. If you are pressed for memory, then explicitly loading/unloading resources between states is the way you want to go. 

 

So, if your game is not too big or if it's going to be run offline as a desktop application, no reason to just do everything in preload.

 

Just my 2 cents and based on my limited experience/understanding of how Phaser does this.

Link to comment
Share on other sites

What is also nice with using a State is the display of the loading. For example I'm coding a PvP multiplayer game. I have a Loadstate where I load all the assets, and some logic to display a loading screen. So the player will see the load bar, some images, and even the load bar of other players. All this "loading" logic is wrapped in a LoadState whose logic is only to deal with loading. 

And in my other states, there is no loading logic whatsoever, which makes them cleaner.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...