scofieldly Posted January 3, 2018 Share Posted January 3, 2018 Hi all, currently I got 2 state stateA assetsA stateB assetsB I want to load assetsB after stateA create completed, so when I go to stateB the preload flow can be faster even to 0. so I wrote like this in the end of stateA create part but I got some wranings this.game.load.audio('stateB1', 'assets/audio/stateB1.ogg'); this.game.load.start(); Phaser.Loader - active loading canceled / reset ----phaser-2.6.2.js:74076 and the assets are not loaded at all. so do you guys now how should I do to 【preload】assets for next state, thx Link to comment Share on other sites More sharing options...
Fenopiù Posted January 3, 2018 Share Posted January 3, 2018 In Phaser you could only preload assets in preload state, so if you want to load other assets after the end of stateA, you have to have another preload state where you preload your assetsB for stateB. Link to comment Share on other sites More sharing options...
scofieldly Posted January 3, 2018 Author Share Posted January 3, 2018 21 minutes ago, Fenopiù said: In Phaser you could only preload assets in preload state, so if you want to load other assets after the end of stateA, you have to have another preload state where you preload your assetsB for stateB. thx for reply, actually I don't want to load assets in the end of stateA, I want to load during the stateA, is that possible? I think there should be some way to do it. but the loading always be reset Link to comment Share on other sites More sharing options...
Fenopiù Posted January 3, 2018 Share Posted January 3, 2018 41 minutes ago, Fenopiù said: In Phaser you could only preload assets in preload state. Link to comment Share on other sites More sharing options...
in mono Posted January 3, 2018 Share Posted January 3, 2018 You can try something like this: let imagesToLoad = ['image1.png', 'image2.png', 'image3.png']; this.game.load.images(imagesToLoad); this.game.load.start(); ... but because (naturally) the images won't load immediately, you have to attach a callback and wait for the loading to complete like this: this.game.load.onLoadComplete.add(this.loadCompleted, this); and then do your stuff in a method called 'loadCompleted' in the same state. Haven't tested it, but it should work. Edit: maybe you should attach the callback twice (once before and once after) if you want to try adding stuff to the load queue right after preload(). If something is already loading, the error is probably because you're calling start() when the loader is still running. Link to comment Share on other sites More sharing options...
Recommended Posts