Wendigo Posted February 24, 2019 Share Posted February 24, 2019 Hi community, I'm trying to add an additional filter to a sprite in Pixi v4 but somehow this only works when I add the filters at the same time like so: mysprite.filters = [new PIXI.filters.BlurFilter(), new PIXI.filters.NoiseFilter()]; My goal is to dynamically add and remove filters on the sprites at a later time. I have tried this (see below), but when I examine the "mysprite.filters" property, the debugger still tells me that there is only one filter on the sprite: mysprite.filters = [new PIXI.filters.BlurFilter()]; ... mysprite.filters.push(new PIXI.filters.NoiseFilter()); What is the correct way to add additional filters to a sprite? Thanks in advance. :) ivan.popelyshev 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 25, 2019 Share Posted February 25, 2019 in v4 there's a getter that clones array, i dont actually remember WHY is it doing that, must be flash legacy. That's why we removed it in v5. and filters is just an array All those things came from flash. You couldn't modify filters array, you had to reassign it. Wendigo 1 Quote Link to comment Share on other sites More sharing options...
Wendigo Posted February 25, 2019 Author Share Posted February 25, 2019 Thanks for the reply. ? Did I get you right, that I have to assign the "active" filters to the "mysprite.filters" array again, each time I want to add/remove one of the filters in Pixi v4? I didn't really understand what you said about the "getter that clones array". Is that an alternative approach to add filters? Do you have a recommendation on how to do this in a memory and performance efficient way? I'm trying to add filter support to the GDevelop game engine so the active filters and filter settings might get changed frequently. Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted February 25, 2019 Share Posted February 25, 2019 I'm talking about this disaster: https://github.com/pixijs/pixi.js/blob/v4.x/src/core/display/DisplayObject.js#L627 PixiJS is not a closed black box like Flash was, its fine to look at sources and think how can you fix it. No, filter objects changes are fine, the problem is only in array of filters. I also recommend to add "filter.filterArea= renderer.screen" option somewhere, like, "use fullscreen mode for filter", i cant give you more details, please read article about filters in v4 in pixijs wiki if you want more. Additional filters are good stuff, but every filter adds one or more framebuffer changes and it can be performance heavy, so beware (unless you have your own stage tree like me that tracks all changes and caches filters. I'm the only one so far who does that ) Quote Link to comment Share on other sites More sharing options...
Wendigo Posted February 27, 2019 Author Share Posted February 27, 2019 Thanks again ? Quote Link to comment Share on other sites More sharing options...
jonforum Posted February 28, 2019 Share Posted February 28, 2019 i remember have a lot of issue by using the prop mysprite.filters What If you use instead mysprite._filters = [...]; On my side no issue with multi filters or my manager but am no using the hell setter . mysprite._filters.push(new PIXI.filters...); ivan.popelyshev and Wendigo 1 1 Quote Link to comment Share on other sites More sharing options...
Wendigo Posted February 28, 2019 Author Share Posted February 28, 2019 Hm, since Pixi 5 is already around the corner, I guess the internal functions of Pixi 4 won't change any more. Might indeed be an option to use the private property. Thanks for the tip. 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.