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?



Share this post

Link to post
Share on other sites

If anyone hasn't seen this error before maybe if I post what I'm trying to do will result in some input, I'm trying to apply the gray filter to the whole state so that everything looks B&W.


Thanks again.

Share this post

Link to post
Share on other sites

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?

Share this post

Link to post
Share on other sites

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 :)

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.