Jump to content

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


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 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.

×
×
  • Create New...