Jump to content

Less features in Pixi v4 Loader than Pixi v3 ?


Mathieu Anthoine
 Share

Recommended Posts

Hi,

I'm working on changing a personal Loader class that inherits from the Loader PixiJs class.

In Pixi v3, I use a middleware called by the after method to add new contents to load during loading and it works very well.

When I try to do the same in Pixi v4, this error occurs: "Cannot add resources while the loader is running."

Is there a way to do the same thing than in Pixi v3 ?

Is it a restriction of Pixi v4 and why ? 

 

Thank you for your help

Link to comment
Share on other sites

There were some change when we moved to resource-loader v2.

Try add "parentResource: resource" to options that you pass to "Add". That's how pixi-spine does it :

function (resource) {

const atlasOptions = {
    crossOrigin: resource.crossOrigin,
    parentResource: resource // <-- this thing
};

this.add(resource.name + '_atlas', atlasPath, atlasOptions, onLoad2); // <-- third param!

}

 

 

Link to comment
Share on other sites

Not sure it would be easy to show you the middleware but here the idea:

1) After loading each resource the middleware checks if it is a json that describes a list of sounds

2) if it's the case, the middleware reads the json and add the url of the sound files listed to the loader with add

3) the middleware call the "next" method to continue the loading process.

4) The process of loading continue correctly and seems to stop when it has to load the files added

 

Link to comment
Share on other sites

Hey Mathieu, the loader from v3 and v4 is the same library. You can checkout this post where I explain why you cannot add root resources to the loader while it is loading:

https://github.com/pixijs/pixi.js/issues/4100#issuecomment-308200817

Quote

Yes, adding a root asset while the loader is running is an error. You can add assets to the loader while it is running, but they must be a child of an existing asset (this is how the spritesheet loader middleware adds image loads based on the json file, for example).

What you are doing is pretty similar to the spritesheet loader, you can see what it does here:

https://github.com/pixijs/pixi.js/blob/04d187991e8415b027f6e314ba5dc89466231ca7/src/loaders/spritesheetParser.js

Restricting loads from middlewares to specify the resource that triggered them fixes a lot of bugs we had before.

Link to comment
Share on other sites

Then its something related to the resource type, how loader does with sounds. Is it BLOB or something else? I don't know and I don't have time to look there.

Either give me a codepen/fiddle to play, either poke those two guys about sounds. @bigtimebuddy made https://github.com/pixijs/pixi-sound , he knows. 

One more way - you can just debug the code - use full (not minified) version of pixi and figure out whats wrong there. I think its about format. For example, i choose XHR_TYPE for some things: https://github.com/pixijs/pixi-spine/blob/master/src/loaders.ts#L49

Link to comment
Share on other sites

On 6/27/2017 at 3:05 AM, Mathieu Anthoine said:

Thank you xerver for your Help,

I tried different things, something close to SpriteSheetParser. I did not have the "cannot add resources" error but stil have a problem,

When the Pixi Loader starts to load my additionnal resource, it stops in the Loader.prototype._loadResource, The _onLoad method is never called

Sounds like you didn't call the `next()` function properly so your asset never "finished" processing. Please share you middleware code.

Link to comment
Share on other sites

Ok I found the bug.

In my homemade framework, I add a version number at the end of files I want to load: fileName.ext?0.1.0 for example

When I add a new file in the loader during loading, if I add an extension to the file, the file is never loaded and the loading never finish

When I remove the extension, the loading works well in pure JS or Haxe.

In Pixi v3, thje loading was working well even with the version at the end of the filename.

Maybe you have changed something in that way ?

Do I need to add an issue on github ?

PS: Adding a version number after a filename, works well when the files are added before loading, the bug occurs only in the special situation describe above

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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