wade.loadScene
rickierich

If I ran loadScene in a thread in javascript, assuming of course that is possible. 

How would I access how loadScene was executing. I am trying to integreate FBs progress bar. I need to be able to workout how far along the loading of the scene is. There is a wade way of doing this but I need to do it the fb way

All 9 Comments
Gio

Hi

wade.getLoadingPercentage() may help you there. As it says in the docs:

Get the percentage of files that have been fully loaded with respect to the number of files for which a loading operation has been requested
Returns number : A number between 0 and 100 indicating the percentage of loaded files

The key thing is that the total is based on the number of assets that you have requested to load. So it will work if you all your assets are part of the scene file, but it won't work accurately if, for example, you load a scene, then when the scene is loaded you try to load more assets.

rickierich

thanks. Just the thread thing to workout.

rickierich

so the solution for facebook is to use preLoadScene with getLoadingPercentage(). 

and loop until with getLoadingPercentage until it is fully loaded. 

Can I assume that if the percentage is 100 that the preLoadScene() has achieved the same synchronous result that LoadScene() would have done?

Gio

To clarify, wade.preloadScene runs ins the same thread as everything else. Nothing in wade is multi-threaded. 

However, wade has its own update loop, so 60 times per second (by default) it will update the simulation and render your game in the canvas(es) that you are using.

While you are loading assets, the simulation is paused and the rendering is paused too, so the canvas will not be updated. But if you preload assets (e.g. using wade.preloadScene), then simulation and rendering are not paused while loading. This does not mean that the loading happens on a different thread.

If you are not displaying the wade canvas while loading, you can use either loadScene or preloadScene, it won't make any difference.

What exactly are your requirements, what are you trying to achieve?

rickierich

I need to set up facebook instant games. 

rather than just mymic progress I am trying to do this.

var images = ['sprite1', 'sprite2', ...];
for (var i=0; i < images.length; i++) {
  var assetName = images[i];  
  var progress = ((i+1)/images.length) * 100;  
  game.load.image(assetName);


  // Informs the SDK of loading progress
  FBInstant.setLoadingProgress(progress);
}

 

The stuff involved with loading the sprites would be replaced by loadScene, but as it is synchronous there is no progress to give facebook progress bar.

The ultimate thing to do is to rewrite loadScene and place a call to facebook progress after everystep. I am not going to take on rewritting loadScene! Looking for an elegant work around.

Gio

It's not really synchronous though, it's just that the game canvas will not update while loading.

Your own scripts will still run, so you can call wade.getLoadingPercentage() in a loop (like within a setInterval) and pass the value to the facebook SDK.

rickierich

I will mimic progress bar, and try and re-write it when I have time, it is only a small change but rather than breaking it now. Maybe wade 4.2 might have FB support. 

Gio

What we can do for 4.2 is add an event such as "onAssetLoaded", so you can add a wade.app.onAssetLoaded function that gets called with data including the number of assets loaded vs number requested etc. From there you can call you platform specific function to set loading progress.

rickierich

that appears to be right. But you should do something comprehensive for facebook instant games.

Post a reply
Add Attachment
Submit Reply
Login to Reply