Jump to content

Why need preload STATE?


Majirefy
 Share

Recommended Posts

In many examples and tutorials, there is usually one "must have" state:

Preload state.

There also discussion on preload state: Do we need load all assets files in preload state?

BTW, I found if I load a sprite sheet from an image file in preload state, and add to game in my main state, sometimes it fails to slice my sprite sheet into each frames. Recently I load an image sprite sheet file for buttons in preload state, and add to my title state, I got the whole image show on the screen, regardless what I set frame width and height in load function in preload state.

Then I put this load into the preload function of title state, it worked well.

So. this made me more confused. Is this a bug? Or there are some rules for file loading?

If we can't load many assets in preload state, why we need it?

Link to comment
Share on other sites

1 hour ago, PhasedEvolution said:

maybe it was being used already? or it is a predefined word

I don't think so.

Later I loaded a sprite sheet image file and gave it "rings" key. It also failed to slice into frames. Then I have to change key to "_rings", then it worked.

So wired. It only happens on sprite sheet image loaded from different state.

Link to comment
Share on other sites

You need a preload state to load the assets needed for the load state. The load state is usually where you load all your game assets (characters, maps, animations etc.), but during this load state you also usually want to display some kind of load bar to inform the player how the loading is going. Those assets you need to load in a separate state, which you usually call the preload state (as it comes right before the load state).

It's no obligation though, but it's the only way to make sure you have your load bars ready when starting the load state.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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