@@ -96,7 +96,6 @@ export default class DemoApplication extends PIXI.Application
96
96
// Setup the container
97
97
this . pond = new PIXI . Container ( ) ;
98
98
this . pond . filterArea = this . filterArea ;
99
- this . pond . filters = this . pondFilters ;
100
99
this . stage . addChild ( this . pond ) ;
101
100
102
101
// Setup the background image
@@ -208,8 +207,6 @@ export default class DemoApplication extends PIXI.Application
208
207
209
208
this . events . emit ( 'animate' , delta , animateTimer ) ;
210
209
211
- this . pond . filters = this . pondFilters ;
212
-
213
210
if ( ! this . animating )
214
211
{
215
212
return ;
@@ -224,7 +221,6 @@ export default class DemoApplication extends PIXI.Application
224
221
const fish = this . fishes [ i ] ;
225
222
226
223
fish . direction += fish . turnSpeed * 0.01 ;
227
- fish . filters = this . fishFilters ;
228
224
fish . x += Math . sin ( fish . direction ) * fish . speed ;
229
225
fish . y += Math . cos ( fish . direction ) * fish . speed ;
230
226
@@ -302,28 +298,45 @@ export default class DemoApplication extends PIXI.Application
302
298
// https://github.com/orgs/pixijs/projects/2/views/4?pane=issue&itemId=48582986
303
299
const toggleFilter = ( enabled ) =>
304
300
{
305
- if ( enabled )
301
+ if ( options . fishOnly )
306
302
{
307
- if ( options . fishOnly )
303
+ const fishFilters = [ ...this . fishFilters ] ;
304
+
305
+ if ( enabled )
308
306
{
309
- this . fishFilters . push ( filter ) ;
307
+ fishFilters . push ( filter ) ;
310
308
}
311
309
else
312
310
{
313
- this . pondFilters . push ( filter ) ;
314
- }
315
- }
316
- else if ( options . fishOnly )
317
- {
318
- const index = this . fishFilters . indexOf ( filter ) ;
311
+ const index = fishFilters . indexOf ( filter ) ;
319
312
320
- if ( index !== - 1 ) this . fishFilters . splice ( index , 1 ) ;
313
+ if ( index !== - 1 ) fishFilters . splice ( index , 1 ) ;
314
+ }
315
+ this . fishFilters = fishFilters ;
316
+ this . fishes . forEach ( ( fish ) =>
317
+ {
318
+ fish . filters = fishFilters ;
319
+ } ) ;
321
320
}
322
321
else
323
322
{
324
- const index = this . pondFilters . indexOf ( filter ) ;
323
+ const pondFilters = [ ...this . pondFilters ] ;
324
+
325
+ if ( enabled )
326
+ {
327
+ pondFilters . push ( filter ) ;
328
+ }
329
+ else
330
+ {
331
+ const index = pondFilters . indexOf ( filter ) ;
332
+
333
+ if ( index !== - 1 ) pondFilters . splice ( index , 1 ) ;
334
+ }
325
335
326
- if ( index !== - 1 ) this . pondFilters . splice ( index , 1 ) ;
336
+ this . pondFilters = pondFilters ;
337
+ // TODO: seems like a bug, requiring invalidation
338
+ this . pond . filters = [ ] ;
339
+ this . pond . filters = pondFilters ;
327
340
}
328
341
} ;
329
342
0 commit comments