A simple editor script for importing spritesheets images into a Godot project by reading and parsing their xml data file.
The script allows to switch the spritesheet image and will correctly update any scene or element using it.
This importer was written to work with those files generated by the Shoebox app, but it can work with any xml file that uses the same structure.
Shoebox is an Adobe Air, so you will need to install it first:
The demo project contains a simple test scene with elements like a TileMap, sprites, and instanced scenes, that uses an imported spritesheet.
This repo includes two folders with different spritesheets so you can switch them inside the project and test the script.
-
Copy the XMLSpritesheetImporter.gd script anywhere into your Godot project.
-
Create a res://image/ folder and put your sprites.png and sprites.xml files inside. The scripts REQUIRES this folder and the files to be named exactly like these.
-
Open the script in the Godot editor.
-
Press ctrl + shift + x to run it.
The script will create an AtlasTexture in resource form (.tres) for every sprite and will organize them into a folder structure according with a naming convention for the individual sprites:
It will parse the name attribute of every xml SubTexture element like this:
Example:
- "obj_crate.png"
Will create a texture resource on path: res://obj/texture/crate.tres
- "fx_explosion_explosion1.png"
Will create a texture on path: res://obj/explosion/texture/explosion1.tres
If the name attribute contains the word tile, it will treat the final texture as part of a tileset and will proceed to create the set as well:
- "tile_grass1.png"
Will create a texture on path: res://tile/texture/grass1.tres
Also, it will create a tileset on: res://tile/tileset.tres, including the tile.
- "tile_world_sand.png"
Will create a texture on path: res://tile/world/texture/grass1.tres
And it will create the tileset: res://tile/world/world_tileset.tres, including the tile.
The parser reads the underscore symbol ("_") in the sprites' names as a folder separator when generating the paths, being the last substring the name of the sprite as such.
So, it's recommended to use camel case for the final sprite name, example:
- "folder_subfolder1_subfolder2_spriteName.png"
The script is pretty simple, and with the use of the XMLParser, Directory, ResourceSaver, ResourceLoader classes, it can be modified to turn it as simple or complex as needed.