It is quite possible to create sprites and animations programmatically, but like other portions of TurtleBrains the heart of quick iterations is with data driven design. As of v0.3.1 .json
is the only supported format, though there is no reason similar structured formats, like .xml
, could be used in the future.
At a bare minimum the sprite sheet must contain a string object, texture
, that contains the path, relative to where the executable runs, to the image used for each sprite, AND an array of objects that describe each sprite frame:
castle_sheet.json
{ "version":1, "texture":"data/castle.png", "sprites":[ { "name":"moat", "x":0, "y":0, "width":100, "height":100 }, { "name":"bridge", "x":100, "y":0, "width":100, "height":100 }, { "name":"flag", "x":200, "y":0, "width":50, "height":50 }, { "name":"tower", "x":0, "y":100, "width":100, "height":200 }, { "name":"gate", "x":100, "y":100, "width":200, "height":200 } ] }
Each sprite object must contain a name that is unique to all others on the same sprite sheet, an x,y coordinate for the top-left pixel location on the texture/image and the width/height in pixel-space on that image. From there it gets a little more advanced. The sprite objects may contain an array of animations.
castle_people_sheet.json
{ "version":1, "texture":"data/castle_people.png", "sprites":[ { "name":"blacksmith", "x":0, "y":0, "width":64, "height":128, "animations":[ "spawn", "idle", "walk", "work" ] } ], "animations":[ { "name":"idle", "sequence":{"width":64, "height":128, "frames":[0, 1, 2, 3] } }, { "name":"ear_twitch", "sequence":{"width":18, "height":18, "frames":[0, 1, 1, 1, 0, 1, 0] } }, { "name":"walk", "sequence":{"width":18, "height":18, "start":2, "count":2 } }, { "name":"eat", "sequence":{"width":18, "height":18, "start":4, "count":2 } } ] }
TODO: TurtleBrains: Documentation: Continue writing about the various forms of animation sequence structures.