What I want to achieve is to be able to drag a Sprite, and when it moves over the interactive area of another Sprite, it emits particles.
However the Pointermove event doesn't get called if I am dragging a different sprite (likely since my pointer is over the draggable sprite, not the interactive sprite.) I tried adding an If-Condition to my drag event instead, which tests if my draggable object is over the interactive Sprite, which sort of works, but it reacts over any area of the sprite, as opposed to exclusively the interactive area. This is important because my Sprite's interactive area uses pixel perfect.
Is there any way to achieve the result I am looking for?
My try with Pointermove:
gameState.chara.setInteractive({cursor: "pointer", pixelPerfect: true});
gameState.chara.on('pointermove', function(activePointer){
if (activePointer.isDown && gameState.clean_cursor) {
switch(gameState.clean_cursor.frame.name.split('_')[0]){
case "sponge":
gameState.bubble.emitParticle(1, activePointer.x, activePointer.y);
break;
case "showerhead":
gameState.splash.emitParticle(1, activePointer.x-50, activePointer.y+50);
break;
}
}
});
this.input.on('drag', (activePointer, gameObject, dragX, dragY) => {
switch(gameObject.frame.name.split('_')[0]){
case "sponge":
gameState.clean_cursor.play('sponge_cursor', true);
break;
case "showerhead":
gameState.clean_cursor.play('shower_cursor', true);
break;
}
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragend', function(pointer, gameObject) {
gameObject.destroy();
gameState.clean_cursor = false;
});
(Pointermove Event stops reacting once I drag the other sprite)
My attempt with Drag only:
gameState.chara.setInteractive({cursor: "pointer", pixelPerfect: true});
this.input.on('drag', (activePointer, gameObject, dragX, dragY) => {
if(gameState.chara.getBounds().contains(dragX, dragY)) {
switch(gameState.clean_cursor.frame.name.split('_')[0]){
case "sponge":
gameState.bubble.emitParticle(1, activePointer.x, activePointer.y);
break;
case "showerhead":
gameState.splash.emitParticle(1, activePointer.x-50, activePointer.y+50);
break;
}
}
switch(gameObject.frame.name.split('_')[0]){
case "sponge":
gameState.clean_cursor.play('sponge_cursor', true);
break;
case "showerhead":
gameState.clean_cursor.play('shower_cursor', true);
break;
}
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragend', function(pointer, gameObject) {
gameObject.destroy();
});
(Works, but over entire sprite, as opposed to the Pixel Perfect interactive Area only)