phaser
phaser copied to clipboard
setCrop keep position relative to GameObject
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.
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();
}
}
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.