I have a sprite that works as a button, but as you press it, it duplicates and lets you drag the duplicate. I've almost got it to work, however currently you have to click first to create a duplicate and are only able to drag after a second click. I'd like to be able to click once and immediately be able to drag.
It is important that the DUPLICATE gets dragged, as opposed to the original, since the original has all the click-functions.
create() {
sprite = scene.add.sprite(0,0, "clean", "showerhead_0000");
sprite.setInteractive({ useHandCursor: true });
sprite.on('pointerdown', () => {
dragTool(scene, options[idx], sprite);
});
this.input.on('drag', function(pointer, gameObject, dragX, dragY) {
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragend', function(pointer, gameObject) {
gameObject.destroy();
gameState.clean_cursor = false;
});
}
function dragTool(scene, option, sprite){
let activePointer = scene.input.activePointer;
let clone = scene.add.sprite(sprite.x,sprite.y, sprite.texture.key, sprite.frame.name);
gameState.clean_cursor = clone;
gameState.clean_cursor.setInteractive();
scene.input.setDraggable(gameState.clean_cursor);
}