Hi,
I’m trying to make a jigsaw puzzle from any given image.
Below is the shape of a jigsaw piece that I intend to cut.
I’ve created the geometric shape for the above jigsaw image as below.
const shape = scene.make.graphics();
shape.fillStyle('0xffffff');
shape.beginPath();
if (this.left_side === 0) {
shape.moveTo(tl.x, tl.y);
shape.lineTo(bl.x, bl.y);
} else if (this.left_side === -1) {
shape.moveTo(tl.x, tl.y);
shape.lineTo(tl.x, Math.floor(tl.y + height / 3));
shape.lineTo(Math.floor(tl.x + width * 0.10), Math.floor(tl.y + height / 3));
shape.lineTo(Math.floor(tl.x + width * 0.15), Math.floor(tl.y + height / 3 + height / 6));
shape.lineTo(Math.floor(tl.x + width * 0.10), Math.floor(tl.y + height / 3 + 2 * height / 6));
shape.lineTo(tl.x, Math.floor(tl.y + height / 3 + 2 * height / 6));
shape.lineTo(bl.x, bl.y);
shape.fill();
.......
Then I made a geometric mask from that shape and assigned it to the image
const mask = shape.createGeometryMask();
sprite.setMask(mask); // sprite is the original image that I'm trying to cut jigsaw pieces from
Now I get a jigsaw piece like below.
Now when I’m trying to drag the jigsaw piece, the image inside the shape is getting dragged, but the jigsaw piece mask is static.
How can I glue the jigsaw piece to the image so both the image and the mask get dragged together.
Or is there a better way to do this?
Appreciate any help to resolve this issue.