Jump to content

Get all sprites?


Jammy
 Share

Recommended Posts

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

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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)

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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