weratius Posted August 27, 2015 Share Posted August 27, 2015 Hi, guys! Here is the problem:I have an interfaceObject that loads it's own resources This is interfacePanels.js >>loadResources: function() { interfaceObj = this; var loader = new Phaser.Loader(game); loader.image('toolbarLeft', 'img/toolbar/toolbar-left.png'); ........... and so on loader.image('enemyInfo', 'img/toolbar/enemy_info.png'); loader.onLoadComplete.add(interfaceObj.init); loader.start(); },init: function() { //chunk of code}And there is another object that uses image with key "enemyInfo" This is playerAvatarBlock.js....enemyBlock = game.add.sprite(playeravatar.x + 120, 10, 'enemyInfo');...Everything works fine when I load all images in BOOT mode, but now I'm trying to use lazy loading and here is a conflict I thought that it doesn't matter how you load images, because all of them will be in one scope How can I solve it? (in console I see that there is no such an image with a key "enemyInfo") THank you =) Link to comment Share on other sites More sharing options...
rich Posted August 27, 2015 Share Posted August 27, 2015 You should use the Phaser.Loader instance that is created automatically when Phaser starts - you can get to it from game.load from your object. Otherwise you're creating a duplicate Loader, with a duplicate load queue, that the Phaser State Manager has no control over, so can't command it to do anything. Link to comment Share on other sites More sharing options...
weratius Posted August 27, 2015 Author Share Posted August 27, 2015 You should use the Phaser.Loader instance that is created automatically when Phaser starts - you can get to it from game.load from your object. Otherwise you're creating a duplicate Loader, with a duplicate load queue, that the Phaser State Manager has no control over, so can't command it to do anything.You mean I have to change in such a way ?game.load.image('enemyInfo', 'img/enemy_info.png');That doesn't work for me I didn't understand that, sorry, couldn't you explain it more detailed? Thank you) Link to comment Share on other sites More sharing options...
Skeptron Posted August 28, 2015 Share Posted August 28, 2015 I think what Rich is saying is that you should never write : var loader = new Phaser.Loader(game);But use instead : game.load.image('image', 'img/image.png'); Link to comment Share on other sites More sharing options...
weratius Posted August 28, 2015 Author Share Posted August 28, 2015 I think what Rich is saying is that you should never write : var loader = new Phaser.Loader(game);But use instead : game.load.image('image', 'img/image.png');I had already tried that and that didn't help at all the images are not loaded Link to comment Share on other sites More sharing options...
Skeptron Posted August 28, 2015 Share Posted August 28, 2015 Do you do as in this example? For both loading and adding to the scene? http://phaser.io/examples/v2/games/starstruck Link to comment Share on other sites More sharing options...
weratius Posted August 28, 2015 Author Share Posted August 28, 2015 Do you do as in this example? For both loading and adding to the scene? http://phaser.io/examples/v2/games/starstruckMy problem is more complex than that example. I have a BOOT file where a lot of images are loaded via "start" method while the game is being preloaded (in other words there is a preloader that is shown and images are being loaded while the preloader exists)preload: function() { game.load.atlasJSONHash('preloader', 'img/preloader/preloader.png', 'img/preloader/preloader.json'); game.load.image('landing', 'img/preloader/Landing.png'); game.load.image('shipPanel', 'img/preloader/ShipPanel.png'); }, create: function() { game.load.onLoadStart.add(this.loadStart, this); game.load.onLoadComplete.add(this.loadComplete, this); this.start(); }, loadStart: function() { //...setting preloader }, loadComplete: function() { //.. some code ... this.game.state.start("Play"); }, start: function() { //--------sprites game.load.image('space', 'img/systemBackgrounds/' + playerInfoObject.system.background + '.png'); //....and sooo onThat is why I'm trying to load some resources when the player enters the game. For example: I don't want to load all my images (100MB) in BOOT mode, I want to load some of them while the player is trying to begin to play It helps user not to waste the time on waiting to be accessed to the game I just need to load some resources in one file, i.e. "interfacePanels.js" and then to use them in other files, i.e. "playerAvatarBlock.js" Thank you) Link to comment Share on other sites More sharing options...
Recommended Posts