Jump to content

Dragging Containers


tsei111
 Share

Recommended Posts

I'm wondering how to drag containers. I have a sprite and I want to have a text underneath and I want to be able to put them in a container together so they are "grouped" and can be dragged around the screen.

 

Partial code below, with assumptions that I'm passing in name and x,y coordinates properly.

    var container;
    var sprite = this.scene.add.existing(this);
    sprite.setTexture(image);
    sprite.setPosition(x,y);

    var txt = this.scene.add.text(x, y+100, name, textConfig).setOrigin(0.5,0.5);

    var container = this.add.container(100,100,[sprite,txt]);
    container.setInteractive();
    this.scene.input.setDraggable(container);

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

 

However, the result is that it doesn't drag but the txt and sprite are within a single container.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...