Lime.embed set root equivalent?


#1

Hello, I’m using openfl es6 for a client and the game will be staticlystored on a CDN , so i can’t use relative path for assets url.

I’ve seen about lime.embed root argument but since lime api isn’t available from npm I’m wondering if there is another way than handling all of the assets preloading myself ? Like with openfl.utils.Assets ?

And i have another question too. ATM i’m loading the assets like in the es6 samples, whith the assets library. It returns a promise for when all the assets are loaded, but is there a way to get the progress, to make a loading screen ?

Thanks you very much for your help


#2

Hi @TBaudon

Sure! I believe the argument is called rootPath, and should be available if you add it to the final argument in the Stage constructor, like this:

var stage = new Stage (550, 400, 0xFFFFFF, App, { rootPath: "path/to/assets" });

The Future type for AssetLibrary.loadFromFile and other like calls has onComplete, onProgress and onError callbacks. onProgress looks like this:

AssetLibrary.loadFromManifest (manifest).onProgress ((bytesLoaded, bytesTotal) => {
    console.log (bytesLoaded, bytesTotal);
}) ...

#3

Awesome !

I thought that was a promise, should have digged the doc a bit more sorry !>_>

Thank you very much for your help and work on this library !

Edit : I tried to use rootPath but it din’t change anything. I looked into the source and i can see the window config but i don’t see where the rootPath or similar argument is used. Do i have something else to do for the rootPath to be used by the assetLibrary and assets ? Thanks

Edit 2 : The on progress event returns NaN and NaN in the parameters, is this a bug I should repport ?


#4

Okay! You’re right – looks like rootPath is handled by lime.embed but not by new Stage in the NPM release. On the other hand, it looks like the way rootPath is handled, it would create some trouble with multiple embeds on the same page. I’ll have to think about this. In the meantime, try setting rootPath on your manifest value:

var manifest = new AssetManifest ();
manifest.addBitmapData ("image.png");
manifest.rootPath = "path/to/assets/root";

AssetLibrary.loadFromManifest (manifest)...

I think that our progress value on loading an asset libraries comes from a size value on each asset entry. We hard-code with the file sizes at compile in the Haxe-based tools, since we don’t always know in advance how large an asset library will be. We should still do our best if this is not defined, though, so yes lets file a bug. I believe onProgress should still work for loading individual files, though


#5

Thank you, I’ll give it a go !


#6

Hello,
I tried to set the root path of the manisfest and it seems to work, thank you !