Skip to content

Conversation

@jdbhartley
Copy link

When using the tool as an alternative to Texture Packer in Godot 4 I noticed that the margins were all set to 0 resulting in either a lot of fixing by hand or being left with sprites unusable for animation.

let sourceSize = {w: item.sourceSize.w, h: item.sourceSize.h};

//Used when importing to Godot Atlas to retain the original sprite size
let margin = {x: (sourceSize.w - spriteSourceSize.w)/2, y: (sourceSize.h - spriteSourceSize.h)/2, h: sourceSize.h - spriteSourceSize.h, w: sourceSize.w - spriteSourceSize.w}
Copy link

@Gerfalerf Gerfalerf Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than splitting the difference of spriteSourceSize and sourceSize, margin.x and margin.y here should simply be set to spriteSourceSize.x and spriteSourceSize.y. Weird that spriteSourceSize is called a "size" when it has an offset like a rect, but those x/y values appear to be the actual offset of the sprite's subregion that was copied into the atlas.

Otherwise, change looks great. Just ran into this issue myself.

@DmitriiPetukhov
Copy link

I also needed this fix, but I ended up creating a custom template based on built-in godot template that also takes margins into account.

I replaced the margin block with:

"margin": {
  "x": {{frame.w | divide : 2 | add : spriteSourceSize.x}},
  "y": {{frame.h | divide : 2 | add : spriteSourceSize.y}},
  "w": {{sourceSize.w}},
  "h": {{sourceSize.h}}
}

End result:

{
  "textures": [
    {
      "image": "{{config.imageFile}}",
      "size": {
        "w": {{config.imageWidth}},
        "h": {{config.imageHeight}}
      },
      "sprites": [
        {{#rects}}
        {
          "filename": "{{name}}",
          "region": {
            "x": {{frame.x}},
            "y": {{frame.y}},
            "w": {{frame.w}},
            "h": {{frame.h}}
          },
          "margin": {
            "x": {{frame.w | divide : 2 | add : spriteSourceSize.x}},
            "y": {{frame.h | divide : 2 | add : spriteSourceSize.y}},
            "w": {{sourceSize.w}},
            "h": {{sourceSize.h}}
          }
        }{{^last}},{{/last}}
        {{/rects}}
      ]
    }
  ],
  "meta": {
    "app": "{{{appInfo.url}}}",
    "version": "{{appInfo.version}}",
    "format": "{{config.format}}",
    "scale": {{config.scale}}
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants