sublime392 / godot-xml-spritesheet-importer

XML Spritesheet Importer script for Godot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

XML Spritesheet Importer

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 Download

Shoebox is an Adobe Air, so you will need to install it first:

Adobe Air Download

Demo

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.

Usage

  1. Copy the XMLSpritesheetImporter.gd script anywhere into your Godot project.

  2. 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.

  3. Open the script in the Godot editor.

  4. Press ctrl + shift + x to run it.

Results

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

Tiles and tilesets

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.

Named tilesets

  • "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.

Recommendations

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"

Tweaking

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.

About

XML Spritesheet Importer script for Godot


Languages

Language:GDScript 100.0%