Jump to content

Pixi's prepare.upload plugin does not always work


Recommended Posts

I am trying to replace a texture atlas of the animated sprite with another one, and play it. I play it once all animations are stopped (variable isAnimation is false). To play it at the time of click, I need to pre upload it to gpu. I am using the following code prepare new texture atlas on each click. 


It seems that prepare.upload does not work everytime! In fact, it only uploads texture every second time. I've put timers into the code, and I can observer that when the prepare.upload uploads to gpu, time difference (variable diff) is 200ms, but when it does not, time difference is just 60ms. Based on that I conclude that prepare.upload didn't upload the textures. 


Now this is a real pain in the ass, because it messes up my animations, sound effect..pretty much renders code useless. What could I do to fix that? I've got over 1000 lines of code and I posted just the relevant stuff. Basically I need to just replace the texture atlas once the animations are over and upload it to gpu. How hard can it be, right? :)






function setupNextSprite(){
            var newLoader = new PIXI.loaders.Loader()
            .add('nextSprite', 'pathToSprote.png')
            .load(function (loader, resources){
                start = +new Date();
                var interval = setInterval(function(){
                    if (!isAnimating){
                        if (!firstRun){
                            nextSprite.textures = setupFrames(resources["nextSprite"].texture.baseTexture);
                            app.renderer.plugins.prepare.upload(nextSprite, function(){
                                console.log("updoaded now");
                                canRunNext = true;
                                isAnimating = false;
                                end = +new Date();
                                var diff = end - start;


// event trigger code
canRunNext = false;


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.

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.


  • Recently Browsing   0 members

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