Install Python. Tested on Python 3, but should also work with 2. Then:
pip install deftree Pillow
python trim.py <path_to_project_root> <path_to_atlas_file> <path_to_output_directory>
This will output PNGs and an animations.lua in the output directory. To convert
the existing sprite to an optimized one:
-
Delete all the animations in the atlas and add the new PNGs (just the frames, without any animation).
-
Require the
animations.luain any script being initialized at the same time or earlier as your sprite component (renaming it as.scriptand attaching it to a game object in the same collection as your sprite also works). -
Make sure your sprite component is positioned at
(0,0)with no rotation or scale within a parent game object itself at(x, y)with no rotation or scale, where(x, y)is the offset of the default animation's first frame. The position and scale of this game object will be controlled by the animation controller, so don't touch them from code. -
Add the animation controller script (
main/animations/sprite_animation.script) next to the sprite component and set thetexture_idproperty to the name of your original atlas file. -
Send the
sprite_play_animationmessage to this script instead ofplay_animationto the sprite. Extra features are available (Read the code).