-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjusted Godot Atlas exporter to take margins into account #85
base: master
Are you sure you want to change the base?
Conversation
@@ -84,6 +84,9 @@ function prepareData(data, options) { | |||
let frame = {x: item.frame.x, y: item.frame.y, w: item.frame.w, h: item.frame.h, hw: item.frame.w/2, hh: item.frame.h/2}; | |||
let spriteSourceSize = {x: item.spriteSourceSize.x, y: item.spriteSourceSize.y, w: item.spriteSourceSize.w, h: item.spriteSourceSize.h}; | |||
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} |
There was a problem hiding this comment.
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.
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
End result:
|
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.