Thank you for your feedback, it seems I should use something with if else but I’dont know how to do that with phaser, this is my code :
create() {
// Drag and drop of the letter A
this.DropzoneA = this.add.image(580, 220, "DropzoneA");
this.DropzoneA.displayWidth = 130;
this.DropzoneA.displayHeight = 130;
// Drop Zone of letter A
this.DropzoneA.setInteractive();
this.DropzoneA.input.dropZone = true;
// The object to be dropped
this.letterA = this.add.image(100, 500, "letterA");
this.letterA.displayWidth = 50;
this.letterA.displayHeight = 90;
this.letterA.setInteractive();
this.input.setDraggable(this.letterA);
this.input.on('dragstart', function (pointer, gameObject) {
this.children.bringToTop(gameObject);
}, this);
this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragenter', function (pointer, _gameObject, _dropZone) {
zone.setTint(0x00ff00);
});
this.input.on('dragleave', function (pointer, _gameObject, _dropZone) {
zone.clearTint();
});
this.input.on('drop', function (pointer, gameObject, dropZone) {
gameObject.x = dropZone.x;
gameObject.y = dropZone.y;
gameObject.setScale(0.0);
gameObject.input.enabled = false;
zone.clearTint();
});
this.input.on('dragend', function (pointer, gameObject, dropped) {
if (!dropped) {
gameObject.x = gameObject.input.dragStartX;
gameObject.y = gameObject.input.dragStartY;
}
});
// Drag and the drop of letterB
this.DropzoneB = this.add.image(400, 220, "DropzoneB");
this.DropzoneB.displayWidth = 130;
this.DropzoneB.displayHeight = 130;
// Drop Zone
this.DropzoneB.setInteractive();
this.DropzoneB.input.dropZone = true;
this.letterB = this.add.image(150, 280, "letterB");
this.letterB.displayWidth = 50;
this.letterB.displayHeight = 90;
this.letterB.setInteractive();
this.input.setDraggable(this.letterB);
this.input.on('dragstart', function (_pointer, gameObject) {
this.children.bringToTop(gameObject);
}, this);
this.input.on('drag', function (_pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragenter', function (_pointer, _gameObject, _dropZone) {
zone.setTint(0x00ff00);
});
this.input.on('dragleave', function (_pointer, _gameObject, _dropZone) {
zone.clearTint();
});
this.input.on('drop', function (_pointer, gameObject, dropZone) {
gameObject.x = dropZone.x;
gameObject.y = dropZone.y;
gameObject.setScale(0.0);
gameObject.input.enabled = false;
zone.clearTint();
});
this.input.on('dragend', function (_pointer, gameObject, dropped) {
if (!dropped) {
gameObject.x = gameObject.input.dragStartX;
gameObject.y = gameObject.input.dragStartY;
}
});
// Drag and drop of the letter C
this.DropzoneC = this.add.image(580, 220, “DropzoneC”);
this.DropzoneC.displayWidth = 130;
this.DropzoneC.displayHeight = 130;
// Drop Zone of letter A
this.DropzoneC.setInteractive();
this.DropzoneC.input.dropZone = true;
// The object to be dropped
this.letterC = this.add.image(100, 500, “letterC”);
this.letterC.displayWidth = 50;
this.letterC.displayHeight = 90;
this.letterC.setInteractive();
this.input.setDraggable(this.letterC);
this.input.on(‘dragstart’, function (pointer, gameObject) {
this.children.bringToTop(gameObject);
}, this);
this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragenter', function (pointer, _gameObject, _dropZone) {
zone.setTint(0x00ff00);
});
this.input.on(‘dragleave’, function (pointer, _gameObject, _dropZone) {
zone.clearTint();
});
this.input.on('drop', function (pointer, gameObject, dropZone) {
gameObject.x = dropZone.x;
gameObject.y = dropZone.y;
gameObject.setScale(0.0);
gameObject.input.enabled = false;
zone.clearTint();
});
this.input.on('dragend', function (pointer, gameObject, dropped) {
if (!dropped) {
gameObject.x = gameObject.input.dragStartX;
gameObject.y = gameObject.input.dragStartY;
}
});
}