Crates.io | sprite-sheet-file-type |
lib.rs | sprite-sheet-file-type |
version | 0.1.1 |
source | src |
created_at | 2024-10-23 06:52:44.259323 |
updated_at | 2024-10-23 06:54:41.711102 |
description | File Type that simplifies SpriteSheet creation |
homepage | |
repository | |
max_upload_size | |
id | 1419780 |
size | 357,622 |
This project aims to create a more convenient sprite sheet file format for use in game development and other graphics applications. Typically, sprite sheets consist of a single image alongside defined rectangles and sprite names to sample from that image. This project seeks to streamline that process.
Here’s a sample code snippet demonstrating how to use the spritesheet
library to create and manipulate sprite sheets.
use sprite_sheet::{SpriteSheet, mapping::{SpriteSheetMetaData, Rect}};
fn main() {
// Create metadata for the sprite
let mut meta = SpriteSheetMetaData::empty();
meta.mapping.insert(String::from("Hello"), Rect { x: 20, y: 20, w: 40, h: 60 });
// Create a new SpriteSheet from an image file
let sheet = SpriteSheet::new_from_path("cat.jpeg", meta).unwrap();
// Save the sprite sheet in PNG format and its metadata in JSON
sheet.save("sheet.png", "sheet.json").unwrap();
// Save the sprite sheet in a raw binary format
sheet.save_raw("raw_image.ssprite").unwrap();
// Retrieve the sprite using its name
let sprite = sheet.get_sprite(&String::from("Hello")).unwrap();
println!("Retrieved sprite: {:?}", sprite.inner.dimensions());
}