Asset Build Tools
Utilities to include in your build.rs
to optimise game assets
Utilities
-
optimise_images(input_folder, output_folder)
- Recursively copy all .png images from the input folder into the output folder, applying heavy file size optimisations such as stripping any data not directly related to reading the image bytes. The folder structure in input_folder is maintained in output_folder. -
optimise_atlas(input_folder, output_folder, tile_size)
- Perform the same optimisations asoptimise_images
, but also interpret each image as a texture atlas and extrude each tile by a fixed amount. A serialisedTextureAtlasLayout
is also saved alongside the image in the output_folder -
build_animations(input_folder, output_folder)
- Recursively search the input folder for animation spec files, and produce an optimised texture atlas image, texture atlas layout, and micro_banimate compatible aniamtion config in the output folder.
build_animations
This utility will search for any files with the .animdata.json
extension, which expects the following format:
pub struct AnimationData {
/// The path relative to the animdata file that contains zero or more sprite sheet fragments, to
/// be built in to the animated atlas
asset_path: String,
/// The dimensions of each frame within a sprite sheet, used to calculate atlas coordinates and inferring row layouts
frame_size: FrameSize,
/// The duration in seconds of each frame in the animation, unless specified otherwise
frame_secs: f32,
/// A map of animation names to their respective frame durations in seconds. Entry names are non-suffixed,
/// relating to the name of the animation without directional information (e.g. "idle" rather than "idle_right_down")
frame_override: HashMap<String, f32>,
/// A list of animation names that should be marked as a loop
should_loop: HashSet<String>,
}
-
asset_path
should point to a folder. The folder should contain images, each of which will be treated as a named animation -
frame_size
should either be a single integer pixel size for square frames (e.g.frame_size: 16
), or a two integer tuple representing width and height for rectangular frames (e.g.frame_size: [8, 16]
) -
frame_override
,should_loop
: The name of the file is the name that will be used in the generated atlas, and so the values provided for looping and overrides should exactly match the file name without the extension