winty Posted May 14, 2015 Share Posted May 14, 2015 Hello all, I'm trying to use the cacheAsBitmap feature in my app. I'm putting a bunch of small objects in a Container to make a larger object, then setting the container to cacheAsBitmap=true, to turn it all into one texture. This all gets done immediately when the large object is created: it creates the container, puts in the sprites, sets the container to cacheAsBitmap, then adds it to the stage to be rendered next frame. I've noticed that when doing this, the object is sometimes randomly not drawn at all. Here's my reproduction case: https://jsfiddle.net/fletcher00/cd6jahh8/8/ . The first sprite is normal, the second one is cached and sometimes doesn't show up. I don't know how this will work on your machines, but for me, the problem is totally sporadic. I can press "Run" 5 times and it won't show up, then it will randomly work fine the next time. Whether it shows up or not seems to depend on some race condition of whether it is cached correctly in time.If on the other hand, I comment out the line "s2.cacheAsBitmap = true;" and uncomment the setTimeout line; that makes it wait one second before setting cacheAsBitmap. When I do that, it works flawlessly every time. So I'm just wondering if there is some way to create an object in its cached state? Or will I have to find a way to create the object, wait a frame for rendering, then call something to set it as cached? Quote Link to comment Share on other sites More sharing options...
winty Posted May 14, 2015 Author Share Posted May 14, 2015 Sorry guys, but I was able to figure this out really quickly with some help from engler... the problem was just that the textures weren't loaded in time. Since they get loaded in a different thread, they still weren't finished by the time the script got to the cacheAsBitmap line. The solution was just using pixi's build-in Loader feature and waiting for it to tell me the texture was finished loading before continuing with the script. Hope this helps someone else out https://jsfiddle.net/cd6jahh8/9/ 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.