Jump to content

Scaling a group with sprites where some have masks breaks the masks


JesperJohansson
 Share

Recommended Posts

I'm working on a "fake zoom" function that looks like this:

class Zoomer extends Phaser.Group {
  zoom = (amount = { x: 1.5, y: 1.5 }) => {
    this.x = -((amount.x * (this.game.width / 2)) - (this.game.width / 2));
    this.y = this.game.camera.bounds.y - (amount.x * (this.game.height * 1.15));
    this.scale.setTo(amount.x, amount.y);
  }
}

The zooming itself works and goes where I want it to but all the masks in the group stay where they are and don't scale at all.

This is how I usually create masks on a Phaser.Sprite:

  createMask() {
    const graphics = this.game.add.graphics(this.x, this.y);
    graphics.beginFill(0xFFFFFF);
    graphics.drawRect(0, 0, this.width, this.height);
    this.addChild(graphics);
    this.mask = graphics;
  }

 

How can I make the group scaling/repositioning include the group's sprites' masks as well?

Edited by JesperJohansson
removed tweens for less code
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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