Jump to content

Error when trying to apply filter


Recommended Posts

I'm using filters as follows:

background = game.add.sprite(0, 0);            background.width = 800;            background.height = 600;            filter = game.add.filter('Gray', game.width, game.height); //error here            filter.alpha = 0.0;            background.filters = [filter];

I get: Uncaught TypeError: undefined is not a function


Firefox gives a bit more info: TypeError: b.Filter[a] is not a constructor


Anyone has any ideas?



Link to comment
Share on other sites

  • 3 weeks later...

I do have trouble with trying the same: 

var gray = this._game.add.filter('Gray');

throws the error "supplied parameters do not match any signature of call target". When I add "null" as another argument, visual studio (or phaser.d.ts) is happy, but the next line,

this._skin.filters = [gray];

throws "cannot convert '{}[]' to 'PIXI.AbstractFilter[]'".


Since those lines are used in a phaser example (Filters > Gray), I am guessing there is something wrong with the phaser.d.ts? Or did pixi update some filters code?

Link to comment
Share on other sites

  • 3 months later...

Hi there !


I had the same problem with the same error when I wanted to apply a pixelating filter to a sprite.


I found a solution, here is what I do :


I'm using a filter from Pixi.js.

I load it :

this.load.script("pixelate", "PixelatePIXI.js");

I apply it on my sprite like that :

MyGame.pixelate = new PIXI.PixelateFilter(); // name of the filter function in PixelatePIXI.jsMyGame.mySpriteToPixelate.filters = [MyGame.pixelate];

(Note that I didn't use the "pixelate" string name I chose when loading the script, so it may not be the right way to do it, but it works fine...)


Hope this helps :)

Link to comment
Share on other sites

  • 1 year later...

Pixi filters are not present in phaser. Thus you need to load them first after downloading from the Phaser repo seperately. Once you load the filter, it makes sense that they may be used directly through the PIXI object which would have not been possible otherwise, because earlier they were not present. Hope I am not stating the obvious.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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