Jump to content

onload event for game.load.image ?


moszis
 Share

Recommended Posts

This might be a really simple question, but I have googled it to death and just cant find the answer..

 

At random times during game run time I need to load new images and display them as sprites.   The way I handled(or attempted) this is by using socket.io on node.   There is always socket open listening to the server.  Message comes in with json object with image information(url, size, name, etc..).    I convert that into array of objects and loop through them to load images using game.load.image.  So far so good.. 

 

The problem is that I dont know how to handle onload event for those images so I can draw sprites.   If I just attempt to add sprites, they are simply showing up as broken images.   The usual javascript onload doesn't seem to work for game.load.images.   I have also seen references to onLoadComplete but that seems to only work for higher level game instance. 

 

Thank you for your help!

Link to comment
Share on other sites

Someone else was doing something similar loading images for avatars and ran into some problems getting them to display. Technically I believe onLoadComplete should fire every time the loader queue completes, so if you add new files to load it should (I think) fire again each time the newly added files are done. However, there does appear to be issues with them showing in Phaser, so I'd have to defer this to someone with more knowledge of this than I do I'm afraid.

Link to comment
Share on other sites

Thanks lewster.   Ran few tests and it seems like the issue is not with onLoadComplete but with actual image loading in Phaser after initial preload ends, which is why onLoadComplete doesn't fire.  

 

  After load.image, I added a ridiculously long wait loop, to be sure that loading should be completed.  Following tried to add that image as sprite.  Sprite shows up as broken image.  

 

  Also tried to call preload() function again and all the images end up broken.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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