html5gamedev Posted May 31, 2017 Share Posted May 31, 2017 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){ clearInterval(interval); if (!firstRun){ nextSprite.textures = setupFrames(resources["nextSprite"].texture.baseTexture); app.renderer.plugins.prepare.upload(nextSprite, function(){ console.log("updoaded now"); canRunNext = true; isAnimating = false; newLoader.reset(); //console.log("kill"); end = +new Date(); var diff = end - start; console.log(diff); }); } } },50); }); } // event trigger code nextSprite.gotoAndPlay(0); canRunNext = false; setupNextSprite(); 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.