Jump to content

resource loader question regarding middleware


andreas_d
 Share

Recommended Posts

Hi guys,

 

Having some trouble trying to use .after() in the loader.  In the following code if I comment out .after()  on('complete') is triggered normally - as are on('load') and on('progress') .  With .after included on('load') and on('progress') fire normally on('complete') fails

	PIXI.loader		.add(assetListA)				.add(assetListB)					.add(assetListC)		.on('load', function(e){			console.log('load')		})		.on('progress', function(loader, resource){			console.log('progress')		})		//.after(function(){console.log('after')})		.on('complete', function(e){ 			console.log('complete')		})		.load() ;

Am I using it wrong?

 

Thanks

Andreas

Link to comment
Share on other sites

A middleware function takes two parameters: resource and next.

Your after middleware is called for each resource that is loaded, the resource parameter is that resource that was loaded. Middlewares are asynchronous, the next parameter is a function that you must call when your middleware has completed its work. The reason complete is never called for you is you never call the next() function, so the library can't know when your parser has completed working.

Link to comment
Share on other sites

I think you misunderstood, your middleware is passed two parameters: the resource that was loaded, and a function to call when you're done.

The library passes you a function to call when you have completed your work, just call it:

	PIXI.loader		.add(assetListA)				.add(assetListB)					.add(assetListC)		.on('load', function(e){			console.log('load')		})		.on('progress', function(loader, resource){			console.log('progress')		})		.after(function(resource, next){console.log('after'); next();})		.on('complete', function(e){ 			console.log('complete')		})		.load() ;
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...