| Crates.io | spottedcat |
| lib.rs | spottedcat |
| version | 0.2.5 |
| created_at | 2025-05-28 09:00:23.405174+00 |
| updated_at | 2026-01-22 01:15:41.162264+00 |
| description | Rusty SpottedCat simple game engine |
| homepage | |
| repository | https://github.com/arion-dsh/spottedcat |
| max_upload_size | |
| id | 1692522 |
| size | 260,696 |
A simple, clean 2D graphics library for drawing images using Rust and wgpu.
Context, Spot, Image, and runAdd to your Cargo.toml:
[dependencies]
spottedcat = { version = "0.1.0" }
use spottedcat::{Context, Spot, Image, DrawOption};
struct MyApp {
image: Image,
}
impl Spot for MyApp {
fn initialize(_context: &mut Context) -> Self {
let image = Image::new_from_file("image.png")
.expect("Failed to load image");
Self { image }
}
fn draw(&mut self, context: &mut Context) {
let opts = DrawOption::default()
.with_position([spottedcat::Pt::from(100.0), spottedcat::Pt::from(100.0)])
.with_scale([2.0, 2.0]);
self.image.draw(context, opts);
}
fn update(&mut self, _context: &mut spottedcat::Context, _dt: std::time::Duration) {}
fn remove(&self) {}
}
fn main() {
spottedcat::run::<MyApp>(spottedcat::WindowConfig::default());
}
ContextDrawing context for managing render commands. Accumulates drawing operations during a frame.
Methods:
new() - Create a new contextbegin_frame() - Clear previous frame's commandsImage::draw(context, options) to queue an image for drawingSpot (trait)Main application trait defining the lifecycle of your app.
Required methods:
initialize(&mut context) - Set up initial state and load resourcesdraw(&mut context) - Render the current frameupdate(event) - Handle events (reserved for future use)remove() - Cleanup on shutdownImageHandle to a GPU texture that can be drawn to the screen.
Methods:
new_from_rgba8(width, height, rgba) - Create from raw pixel datanew_from_file(path) - Load from image file (PNG, JPEG, etc.)new_from_image(image) - Clone an existing imagesub_image(image, bounds) - Extract a region from an imagedestroy() - Free GPU resourcesDrawOptionsOptions for controlling how images are rendered.
Fields:
position: [f32; 2] - Top-left corner in screen pixelsrotation: f32 - Rotation in radiansscale: [f32; 2] - Scale factors (applied after the image's intrinsic size)BoundsRectangle for defining sub-regions of images.
Fields:
x: u32 - X coordinatey: u32 - Y coordinatewidth: u32 - Widthheight: u32 - Heightrun(init)Main entry point. Creates a window, initializes graphics, and runs the event loop.
Arguments:
init: fn(&mut Context) -> Box<dyn Spot> - Function to create your appExtract regions from existing images without duplicating GPU memory:
let full_image = Image::new_from_file("spritesheet.png")?;
let sprite = Image::sub_image(
full_image,
Bounds::new(0, 0, 32, 32)
)?;
let opts = DrawOption::default()
.with_position([spottedcat::Pt::from(400.0), spottedcat::Pt::from(300.0)])
.with_rotation(std::f32::consts::PI / 4.0) // 45 degrees
.with_scale([2.0, 2.0]); // Double size
image.draw(&mut context, opts);
let mut rgba = vec![0u8; 64 * 64 * 4];
// Fill with your pixel data...
let image = Image::new_from_rgba8(64, 64, &rgba)?;