combineSprites method

void combineSprites(
  1. List<int> combine
)

Implementation

void combineSprites(List<int> combine){
  int? x1;
  int? y1;
  int? x2;
  int? y2;
  combine.sort();
  Vector3 newPos = sprites[combine[0]].position;
  double cameraX = camera.position.x;
  double cameraY = camera.position.y;

  for(int i = 0; i < combine.length; i++){
    int widthS = sprites[combine[i]].sprite.width;
    int heightS = sprites[combine[i]].sprite.height;

    int positionX = (sprites[combine[i]].position.x*100-(cameraX*100)).round();
    int positionY = (sprites[combine[i]].position.y*-100+(cameraY*100)).round();

    if(x1 == null || x1 > positionX){
      x1 = positionX;
      newPos.x = sprites[combine[i]].position.x;
    }
    if(y1 == null || y1 > positionY){
      y1 = positionY;
      newPos.y = sprites[combine[i]].position.y;
    }

    if(x2 == null || widthS+positionX > x2){
      x2 = widthS+positionX;
    }
    if(y2 == null || heightS+positionY > y2){
      y2 = heightS+positionY;
    }
  }
  Offset offset = Offset(-x1!*1.0,-y1!*1.0);
  _generateImage(Size((x2!-x1)*1.0,(y2!-y1)*1.0), combine, offset).then((value){
    sprites.add(
      SpriteImage(
        sprite: value,
        name: sprites[combine[0]].name,
        position: newPos
      )
    );
    for(int i = combine.length-1; i >= 0; i--){
      sprites.removeAt(combine[i]);
    }
  });
  updateTapLocation(const Offset(0,0));
}