Simple Sprite Dragging

Demonstrates how to make a sprite interactive, enable it for dragging, and use the drag event to update its position as the pointer moves.

Simple Sprite Dragging, running
360 × 640
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.image('apple', 'assets/sprites/apple.png');
    }

    create ()
    {
        const apple = this.add.sprite(100, 100, 'apple');

        apple.setInteractive();

        this.input.setDraggable(apple);

        this.input.on('drag', (pointer, gameObject, dragX, dragY) =>
        {

            gameObject.x = dragX;
            gameObject.y = dragY;

        });
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    width: 360,
    height: 640,
    _parent: 'game-container',
    backgroundColor: '#efefef',
    scene: Example
};

const game = new Phaser.Game(config);

More in Dragging22 examples