andreas_d Posted August 12, 2015 Share Posted August 12, 2015 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? ThanksAndreas Quote Link to comment Share on other sites More sharing options...
xerver Posted August 12, 2015 Share Posted August 12, 2015 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. Quote Link to comment Share on other sites More sharing options...
andreas_d Posted August 12, 2015 Author Share Posted August 12, 2015 Wow that's pretty comprehensive xerver. Someone would think you wrote the damn thing Is next() a custom function of my own? If so how do I communicate with the library from within the next function ? how do I tell it to 'continue'? Quote Link to comment Share on other sites More sharing options...
xerver Posted August 12, 2015 Share Posted August 12, 2015 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() ; Quote Link to comment Share on other sites More sharing options...
andreas_d Posted August 13, 2015 Author Share Posted August 13, 2015 ahh ok i get it now. Thanks for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.