phaser icon indicating copy to clipboard operation
phaser copied to clipboard

setCrop keep position relative to GameObject

Open FelipeIzolan opened this issue 1 year ago • 1 comments

image

Hi! I was coding a minimap to my game world that get a frame from the minimap-image relative to player-position by setCrop, but the minimap not stay fixed, because position is relative to texture.

It would be nice, a setCrop that works like the native method drawImage, where the position stay the same, just the rectangle-frame change.

FelipeIzolan avatar Jan 15 '24 21:01 FelipeIzolan

Ok! I solved my problem with:

class Scene {
  preload() {
    this.load.image("minimap", "/minimap.png");
  }

  create() {
    this.minimap = this.add.image(0, 0, "minimap");
    this.minimap.frame.cutWidth = 64;
    this.minimap.frame.cutHeight = 64;
  }

  update() {
    this.minimap.frame.cutX = {PLAYER_POSITION_X};
    this.minimap.frame.cutY = {PLAYER_POSITION_Y};
    this.minimap.frame.updateUVs();
  }
}

But it would be nice a high-level method that do:

class Image {
  ...

  setCut(x, y, width, height) {
    this.frame.cutX = x;
    this.frame.cutY = y;
    this.frame.cutWidth = width;
    this.frame.cutHeight = height;
    this.frame.updateUVs();
  }
}

FelipeIzolan avatar Jan 16 '24 20:01 FelipeIzolan

Thanks for your feature request.

We are pleased to inform you that setCutPosition and setCutSize methods have been added.

This update will be available in the next Phaser release.

zekeatchan avatar Jun 18 '24 06:06 zekeatchan