MichaelD

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?

 

Thanks!

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.