spottedcat
A simple, clean 2D graphics library for drawing images using Rust and wgpu.
Why spottedcat?
The library is named after the Rusty-spotted cat (Prionailurus rubiginosus), the world's smallest wild cat. Just like its namesake, this library aims to be tiny, agile, and remarkably efficient.
Features
- Simple API: Minimal core types to learn:
Context,Spot,Image,Text, andrun. - GPU-accelerated: Built on wgpu for high-performance rendering.
- Image operations: Load from files, create from raw data, extract sub-images.
- Text rendering: Custom font support, text wrapping, and styling (color, stroke).
- Audio support: Play sounds (PNG/WAV/etc.), sine waves, and handle fades/volume.
- Input management: High-level API for Keyboard, Mouse, and Touch events.
- Scene management: Easy switching between game scenes with payload support.
- Resource management: Built-in dependency injection for shared resources.
- Cross-platform: Support for Desktop, Web (WASM), IOS and Android.
Quick Start
Add to your Cargo.toml:
[]
= "0.3.0"
Basic Example
use ;
use Duration;
API Overview
Core Components
Context: Central state for managing draw commands, input, audio, and resources.Spot: Trait defining application lifecycle (initialize,update,draw,remove).Image: GPU texture handle for drawing. Supports sub-images and raw data creation.Text: High-level text rendering with font registration and layout.DrawOption: Unified configuration for position, rotation, scale, and clipping.
Key Systems
- Input: Check keys with
key_down, mouse withmouse_button_pressed, or gettouches. - Audio: Load and play sounds with
play_sound, or generate tones withplay_sine. - Scenes: Transition between states using
switch_scene::<NewScene>(). - Resources: Share data between systems via
context.get_resource::<T>().
Platform Support
- Desktop: Windows, macOS, Linux.
- Web: Compile to WASM with
wasm-pack. Seecanvas_idinWindowConfig. - Android: Integrated with
winit's android-activity.
License
This project is licensed under either of:
- Apache License, Version 2.0
- MIT license
at your option.