Exemplo n.º 1
0
 @Override
 public Sprite getTileSprite(Sprite sprite, double dX, double dY, double xScale, double yScale) {
   serviceRectangle.setCoords(sprite.getX() * xScale + dX, sprite.getY() * yScale + dY);
   serviceRectangle.setSize(sprite.getWidth() * xScale, sprite.getHeight() * yScale);
   serviceRectangle.shapeType = sprite.shapeType;
   return serviceRectangle;
 }
Exemplo n.º 2
0
  public static SpriteTemplate fromSprites(
      LinkedList<Sprite> sprites, Layer layer, Shape pivotShape, Relativity relativity) {
    SpriteTemplate template = null;
    double leftX = 0d, topY = 0d, rightX = 0d, bottomY = 0d;
    Sprite newSprite = new Sprite();

    for (Sprite sprite : sprites) {
      if (sprite.shapeType.getNum() == ShapeType.spriteTemplate.getNum()) continue;
      if (template != null) {
        leftX = Math.min(leftX, sprite.leftX());
        topY = Math.min(topY, sprite.topY());
        rightX = Math.max(rightX, sprite.rightX());
        bottomY = Math.max(bottomY, sprite.bottomY());
      } else {
        template = new SpriteTemplate();
        leftX = sprite.leftX();
        topY = sprite.topY();
        rightX = sprite.rightX();
        bottomY = sprite.bottomY();
        if (pivotShape == null) pivotShape = sprite;
      }
    }

    if (template != null) {
      newSprite.setCoords(0.5d * (leftX + rightX), 0.5d * (topY + bottomY));
      newSprite.setHeight(bottomY - topY);
      newSprite.shapeType = template;
      if (layer != null) layer.insert(newSprite, pivotShape, relativity);

      for (Sprite sprite : sprites) {
        if (sprite.shapeType.getNum() == ShapeType.spriteTemplate.getNum()) continue;
        layer.remove(sprite);
        sprite.setCoords(
            (newSprite.getX() - sprite.getX()) / newSprite.getWidth(),
            (newSprite.getY() - sprite.getY()) / newSprite.getHeight());
        sprite.setSize(
            sprite.getWidth() / newSprite.getWidth(), sprite.getHeight() / newSprite.getHeight());
        template.sprites.addLast(sprite);
      }
    }

    return template;
  }