These are chat archives for pixijs/pixi.js

27th
Feb 2017
schoening
@schoening
Feb 27 2017 06:07
@englercj yeah, I noticed the z-order example uses a plugin. I have three questions then. 1. Is removing objects from the stage creating any garbage? 2. Is swapping children creating garbage? I have a very large world and I think I need to do a lot of sprite
Whoops.. Mobile... Wasn't finished typing..
... swapping / manual frustum culling. 3. Is swapping textures expensive? ... Im targeting mobile and gonna have a couple of thousand sprites UNLESS I swap things out and only render the surrounding area. So it's not so much premature optimisation but stuff I really do need. Hope you have the time to answer at some point :)
Josh Groves
@grovesNL
Feb 27 2017 17:14
@schoening For (1), if you're constantly resizing the stage every frame you'll probably incur some GC. It's better to test this with your expected stage size and check how badly it hits GC. The last time I tried that in Pixi v3, it was more effective to perform manual frustrum culling but v4 may have improved this. I think there is also a way to hide sprites but leave them attached to the stage (i.e. if you plan to display it again), so you could just hide/show sprites and only remove them after you don't plan on showing them again. You'd have to test each approach to check which one is faster for your case.
For (3), swapping textures is generally expensive if you have to reupload it to the GPU and it will depend on the size of the texture. I don't know whether Pixi v4 optimizes this (i.e. leaving unused textures on the GPU as long as it can to avoid reuploading them). I recommend creating a test case for this too.
schoening
@schoening
Feb 27 2017 17:39
Appreciate the great reply @grovesNL . I know you are right and I have to do some tests to be sure for my particular usecase.. I did however hope/think that gc does not get triggered as long as I keep references of the sprites somewhere else in my program (like a object pool).
Swapping textures is expensive huh.. How do you do animations?
Josh Groves
@grovesNL
Feb 27 2017 18:17
@schoening The GC would be with Pixi's objects internally, i.e. resizing arrays or anywhere they track the objects for the stage.
For animations they should be put into one large image (i.e. a sprite sheet). So it's the same texture, it will get uploaded to the GPU once but it can animate a sprite by moving to different offsets within that texture
schoening
@schoening
Feb 27 2017 18:30
@grovesNL thanks for the explaination. I have looked into sprite sheets and wondered if they benefit performance or just load time. Sucks to not have a good grasph of webgl I gotta change that. So 100 sprites using the same sprotesheet will still only upload the texture once?
Josh Groves
@grovesNL
Feb 27 2017 18:33
@schoening Yep although there are also limits to how large your sprite sheet can be (a lot of people don't try to use bigger than 1024x1024 or 2048x2048 which is relatively quite large), so you could play around with it a bit to see what works best for you. i.e. if certain scenes require different images then you could have different sprite sheets for that scene
schoening
@schoening
Feb 27 2017 18:41
Thanks for all the help. I will use a couple if them also for sanity reasons I think
However, I am gonna need to do z-order stuff, have you played around with swapping the children in a container?
Josh Groves
@grovesNL
Feb 27 2017 19:30
@schoening No sorry, it's been a while since I've looked at it. I mostly just know about WebGL
schoening
@schoening
Feb 27 2017 19:43
Np :smile: