Jump to content

Best way to update group sprite positions while being dragged?


Mike018
 Share

Recommended Posts

For dragging groups consisting of multiple sprites to make up 1 "sprite", is this the best way to go about it? Just updating all the sprites to the position of the dragged 'primary' sprite when the drag is active? It works, but it seems pretty inefficient and the update method would get crowded if I had a lot of groups that need to be dragged.

     createBee() {
      this.beeWingBack = this.create(
        x,
        y,
        'atlas1', 'objects/beeWingQueenBack'
      );
      this.beeBody = this.create(
        x,
        y,
        'atlas1', 'objects/beeBodyQueen'
      );
      this.beeFace = this.create(
        x,
        y,
        'atlas1', 'objects/beeFaceQueenDefault'
      );
      this.beeWingFront = this.create(
        x,
        y,
        'atlas1', 'objects/beeWingQueenFront'
      );
    }
    
    activateDrag() {
      this.beeBody.inputEnabled = true;
      this.beeBody.input.enableDrag();
      this.dragEnabled = true;
    }

    update() {
      if(this.dragEnabled === true) {
        this.beeFace.position.x = this.beeBody.position.x;
        this.beeFace.position.y = this.beeBody.position.y;
        this.beeWingFront.position.x = this.beeBody.position.x;
        this.beeWingFront.position.y = this.beeBody.position.y;
        this.beeWingBack.position.x = this.beeBody.position.x;
        this.beeWingBack.position.y = this.beeBody.position.y;
    }

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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