anchor doesn't work in custom filter

Recommended Posts

I wrote a filter to achieve special effects. Part of the code is as follows,scale and rotate works well,but the anchor I set seems not right,the sprite still rotates around the upper left corner.

constructor(texture:PIXI.Texture) {
            super(MyFilter.vertSrc, MyFilter.fragSrc)
            this.maskMatrix = new PIXI.Matrix();  
            let sprite = new PIXI.Sprite(texture);
            sprite.visible = false;

            this.maskSprite = sprite;
            this.maskSprite.anchor.set(0.5)     //it doesn't work!
            this._translate = [0, 0];
            this.uniforms.mapSampler = sprite.texture;
            this.uniforms.filterMatrix = this.maskMatrix;

        translate(x:number, y:number) {
            this._translate[0] = x;
            this._translate[1] = y;
            this.uniforms.vTranslate = this._translate;

        scale(x:number, y:number) {
            this.maskSprite.scale.set(x, y);
        rotate(rad:number) {
            this.maskSprite.rotation = rad;


Share this post

Link to post
Share on other sites

calculateSpriteMatrix takes anchor into account:

It should work. You've made a mistake in a place that is hidden from my telepathy, please provide a demo on codepen/jsfiddle/pixi-playground.

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.

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.


  • Recently Browsing   0 members

    No registered users viewing this page.