soimy / atlasify

GPU friendly assets packer using max-rects algorithm
https://atlasify.nanoo.app
MIT License
31 stars 4 forks source link

Support for multiple sprites (bug?) #8

Closed mnovbaalen closed 4 years ago

mnovbaalen commented 5 years ago

Atlasify is a great way to generate spritesheets!

However, when there are more images than fit on the spritesheet, Atlasify generates multiple spritesheet files with the same name. This results in having a spritesheet file with only the remainder of images that did not fit on the previous spritesheet(s).

Some info that might help: The problem seems to be in atlasify.ts / atlasify.js, in the pack function. The binName is not unique when no tags are used. When

            let binName = basename;

is replaced with

            let binName = basename + '_' + index;

then multiple spritesheet files are generated.

This is not a good solution, but just a quick 'see if this helps' hack for my specific use case.

Please fix this in a proper way.

soimy commented 5 years ago

Thanks for the report, I'll look into it.

soimy commented 5 years ago

Fixed via c554cdb Should work as you expected now.

mnovbaalen commented 5 years ago

Thank you very much @soimy, I'll give it a try!

mnovbaalen commented 4 years ago

@soimy I'm very sorry for this late reply, but I can confirm that the fix works for me!

EDIT: I found one thing that is not working correctly yet: In the generated json files, that are now postfixed by an index, the value of the "image" tag in the "meta" tag has the image filename without the index postfix.

mnovbaalen commented 4 years ago

@soimy I made this change to atlasify.ts to get things working:

--- src/atlasify.ts (date 1578929561671)
+++ src/atlasify.ts (date 1578929561671)
@@ -329,11 +329,12 @@
             // Add tag to the last sheet to control mustache trailing comma
             serializedSheet[serializedSheet.length - 1].last = true;

+            const spritesheetId = tagCount[tag];
             // prepare spritesheet data
             this._spritesheets[index] = {
-                id: tagCount[tag],
+                id: spritesheetId,
                 name: binName,
-                imageName: `${binName} .${ext}`,
+                imageName: `${binName}.${spritesheetId}.${ext}`,
                 imageFormat: "RGBA8888",
                 width: bin.width,
                 height: bin.height,
soimy commented 4 years ago

Thanks for the report

mnovbaalen commented 4 years ago

Thank you @soimy for fixing this. It is working correctly now.