Spritesheet exporter: exports as spritesheets


Why use it

Most pixel art games use spritesheets for their animations, but manually exporting from the animation timeline is a pain, effectively destroys your animation if you do it on the same file, and with every new modification you need to start all over again.
This plugin allows you to easily export the active animation as a spritesheet without modifying your current working document.


How to use it

Tools > Scripts > Export As Spritesheet will export the animation from the currently selected document's animation timeline.


Options

export name: if you type in "exportName", the name of the individual exported frames will be exportName_000.png, exportName_001.png, etc., and the spritesheet will be called exportName.png . If your name contains a comma, anything after the first comma will be ignored, and the file will still export as a png (for example, "exportName", "exportName.png", "exportName.pdf", "exportName.v12.final.finalfinal.xcf" will all export to the same name, see example just above).
export directory: select the folder in which the spritesheet will be exported (the frames will be exported in a subfolder of the export directory called exportName_sprites if no sprites export directory is set)
change export directory: Opens a file explorer to select the Export Directory
reset to current directory: Resets the export directory to the directory containing the currently active .kra document
write json texture atlas: Writes a json texture atlas file that can be used e.g. in the Phaser 3 game framework. The atlas filename will be "exportName.json" The filenames in the atlas file will be set to the numeric index of the texture. Example:

{ "frames": [
    { "filename": 0,
      "frame": { "x": 0, "y": 0, "w": 300, "h": 334 } },
    { "filename": 1,
      "frame": { "x": 300, "y": 0, "w": 300, "h": 334 } },
...

use layers as animation frames: instead of exporting a spritesheet using each frame, export one using each visible layer (for the current frame); for people who have files formatted the photoshop way (timeline and layers on the same axis), or for those who don't export actual animations but sketches or something
export direction: How the frames are placed. For example, in a 3*2 grid, frame numbers are as follows:
if horizontal:
1, 2, 3
4, 5, 6
if vertical:
1, 3, 5
2, 4, 6
rows: select the number of rows. If 0, the script will guess it using the number of columns.
columns: select the number of columns. If 0, the script will guess it using the number of rows (it might change the number of rows to respect the horizontal priority)
If both rows and columns are set to 0, the default value will be used for both (I'm torn between the default being one row or a square-ish image, I'd love to hear what other people think about this)
start and end: the start and end of the animation to export to spritesheet. Anything outside those values will not be considered.
step: Only consider every 'step' frame when exporting to spritesheet
If start and end are both set to -1, it will use the default value for both (that is, the actual animation length, considering all visible layers)
remove individual sprites: whether to remove the folder containing the individual exported sprites once finished. You'll usually want this on, but you do you.
force new folder: if the export folder already exists, whether to create a new one in its parent directory (checked), or export in it anyway, potentially overwriting existing files (unchecked).


Other spritesheet manipulations

If you want to import spritesheets, just use the built-in tools and simply (with your spritesheet open) go to Image > Image Split then (in a new file of the same dimensions as one frame), File > Import Animation Frames (official tuto with images here)
If you want to merge existing spritesheets, open the biggest one to get a document its size, then remove or hide it so your document is empty, then import each spritesheet on a different frame (File > Import Animation Frames) and export them as a spritesheet (Tools > Scripts > Export As Spritesheet); you probably want 1 column and 0 (default) rows if your individual spritesheets are each one line


Notes

If you want to activate debug messages:
- go to the uispritesheetexporter.py file and change the second to last line, from "self.exp.export()" to "self.exp.export(True)"; it will print the debugs in the terminal (if you launched krita through the terminal)
- if you don't use the terminal, do the first step, then go to spritesheetexporter.py and change line 80 from "def debugPrint(message, usingTerminal = True):" to "def debugPrint(message, usingTerminal = False):" ; it will print the debug messages in small pop-up windows that you will have to click ok on before the script can go on.

If you have comments, suggestions, or need to contact me, send me an email at: noemie.scherer@gmail.com or open an issue at https://github.com/Falano/kritaSpritesheetManager (which is also where you can re-download it in case of need)