Jammy Posted June 2, 2017 Share Posted June 2, 2017 Hi guys, Not too sure where to find this or if it's possible but is there a way to get an array or object containing all the sprites that are currently in the renderer? Thanks, Jammy. Quote Link to comment Share on other sites More sharing options...
themoonrat Posted June 2, 2017 Share Posted June 2, 2017 function recursiveFindSprites( spriteArray, displayObject ) { if ( displayObject.texture ) { spriteArray.push( displayObject ); } if ( Array.isArray( displayObject.children ) ) { for ( let i = 0; i < displayObject.children.length; ++i ) { recursiveFindSprites( spriteArray, displayObject.children[i] ); } } }; let spriteArray = []; recursiveFindSprites( spriteArray, renderer._lastObjectRendered ); Slightly hacky in that it's looking for a .texture property, which will also include Sprite like items like Text and such, but that's the if statement to fine tune for your needs Quote Link to comment Share on other sites More sharing options...
Jammy Posted June 2, 2017 Author Share Posted June 2, 2017 @themoonrat thanks dude appreciate it - it appears to work for the time being although it doesnt appear to find a container that has been rendered with renderTexture which maybe require more hacking I guess? When I ran it - it created an enormous array but it doesn't feel like my sprites are that many... I'll do some comparisons and get to grips with just what this code means I think. Maybe there really are 1800 sprites (sprites/text) in my one scene hahaha. Whadya think to expanding this code into a "inspector" like firebug but for pixi? Quote Link to comment Share on other sites More sharing options...
themoonrat Posted June 2, 2017 Share Posted June 2, 2017 Yeah... think of rendertextures like when editing an image in photoshop, and you have all these layers, and when you come to save a png or jpg it asks if you're ok flattening everything into 1 layer. That's your rendertexture, so it's not going to show up in the scene graph all of the things that went on to make it up. And there is a chrome plugin inspector https://github.com/bfanger/pixi-inspector & https://chrome.google.com/webstore/detail/pixi-inspector/aamddddknhcagpehecnhphigffljadon?hl=en I found it didn't play nicely and got confused by renderTextures, for which I have my own hacked version of to solve, but the above might play out of the box nicely for you (the github version seems newer than the chrome store version, but didn't work for me at all) Quote Link to comment Share on other sites More sharing options...
Jammy Posted June 3, 2017 Author Share Posted June 3, 2017 @themoonrat oh cheers dude didn't see that inspector before, doesn't seem to work though even from a fresh build - i'll use the script you gave me for now it does the job, thanks 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.