Dragging Containers

I’m wondering how do I go about dragging containers.

I’ve had it setup as such so that there would be text below above a sprite and that on drag they would move together. However, it doesnt seem to work at all and does not drag. If someone could point me into the right direction that would be appreciated. Thanks for reading.

// spriite and txt defined here.

var container = this.add.container(500,500);
container.add(sprite);
container.add(txt);
container.setSize(250,250);
container.setInteractive({ draggable: true });

this.scene.input.on(‘drag’,function (pointer,gameObject,dragX,dragY){
gameObject.x=dragX;
gameObject.y=dragY;
});

Containers have no texture, so there’s nothing for the pointer to drag; you’ll need to define a hitArea.

1 Like

I looked at some other post on diff forums and it said that if you pass no hit area to setInteractive() it will become a rectangle shape around the container?

Apologies I’m very new to phaser could you tell me how I would be able to set hit area in this scenario?
Is it done by calling setInteractive( new Phaser.Rectangle(0,0, 100, 100)); ?

edit: Nevermind I think its container.hitArea = new Phaser.Rectangle( 0,0, 250, 250);