I have some sprites that are set to horizontal drag only.

What I want to do is, if someone drags vertically up from one of those sprites, when they leave the bounds of that sprite (top edge), spawn a new sprite and be actively dragging that new sprite. The user should not have to release the mouse button, they should just instantly be dragging the new sprite.

I can successfully calculate when the pointer is leaving the first sprite, and spawn a new sprite at that location, but I can't seem to transfer the drag control.

I tried Pointer.swapTarget, but that doesn't seem to work - the new sprite is spawned, but just sits there and I have to release the mouse button and re-click on the new sprite in order to drag it.

How can I make the transfer seamless?


1 Answer 1


Without code I'm not exactly sure what you're doing for the dragging now.

So, I see two options:

  1. Spawn a new sprite where the old one was before and let the one that was being dragged continue to be dragged.
  2. Instead of using the sprite for your logic, use the pointer itself. (One of the paid Zenva tutorials went this route.)
    1. In your update() check if this.game.input.activePointer.isDown. If it is, and it's over your sprite, make note that you're dragging the sprite in a 'global' variable, like this.isDraggingSprite. You might already have this.
    2. Get the current position of the pointer and spawn a new sprite at that location. ('Globally' accessible so that you can check whether or not it is alive.
    3. Let the new sprite follow the position of the pointer until is isUp.
    4. Create a new sprite at the finished position and kill the one that was being dragged. Set this.isDraggingSprite = false;.

Globally accessible meaning somewhere it be accessed across updates, which you might already have defined on your game object.

Depending upon how you have things coded now, and what sort of effect you want, one option might be better than the other.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .