Majirefy Posted March 1, 2017 Share Posted March 1, 2017 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 More sharing options...
PhasedEvolution Posted March 1, 2017 Share Posted March 1, 2017 I am not sure what is happening. The phaser preload State makes sure that the textures and other files are already loaded before any of the game elements that use those files are generated. Yes, you should load all your assets on the preload. Link to comment Share on other sites More sharing options...
samme Posted March 1, 2017 Share Posted March 1, 2017 You may or may not create and use a separate state dedicated to preloading assets. Assets must be loaded in a preload callback (of any state) before they can be used. Link to comment Share on other sites More sharing options...
Majirefy Posted March 2, 2017 Author Share Posted March 2, 2017 @PhasedEvolution @samme I know what's wrong. I set the key of sprite sheet is "buttons". After I changed it to "_buttons", it works. But I don't know why. Link to comment Share on other sites More sharing options...
PhasedEvolution Posted March 2, 2017 Share Posted March 2, 2017 1 hour ago, Majirefy said: @PhasedEvolution @samme I know what's wrong. I set the key of sprite sheet is "buttons". After I changed it to "_buttons", it works. But I don't know why. maybe it was being used already? or it is a predefined word Link to comment Share on other sites More sharing options...
Majirefy Posted March 2, 2017 Author Share Posted March 2, 2017 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 More sharing options...
Skeptron Posted March 3, 2017 Share Posted March 3, 2017 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 More sharing options...
Recommended Posts