Expand description
§spottedcat
Spottedcat is a lightweight cross-platform 2D/3D game engine built with Rust and wgpu. It provides a simple API for rendering, input, audio, text, and scene management across desktop, web, iOS, and Android. Designed for fast prototyping and creative interactive projects, it aims to stay small, practical, and easy to use.
§Basic Example
use spottedcat::{Context, Spot, Image, DrawOption, Pt, WindowConfig};
use std::time::Duration;
struct MyApp {
image: Image,
}
impl Spot for MyApp {
fn initialize(ctx: &mut Context) -> Self {
// Create an image from raw RGBA8 data
let rgba = vec![255u8; 64 * 64 * 4]; // Red square
let image = Image::new(ctx, Pt::from(64.0), Pt::from(64.0), &rgba)
.expect("Failed to create image");
Self { image }
}
fn update(&mut self, _ctx: &mut Context, _dt: Duration) {
// Handle logic here
}
fn draw(&mut self, ctx: &mut Context) {
let (w, h) = spottedcat::window_size(ctx);
// Draw image at center
let opts = DrawOption::default()
.with_position([w / 2.0, h / 2.0])
.with_scale([2.0, 2.0]);
self.image.draw(ctx, opts);
}
fn remove(&mut self, _ctx: &mut Context) {}
}
fn main() {
spottedcat::run::<MyApp>(WindowConfig {
title: "SpottedCat Example".to_string(),
..Default::default()
});
}Re-exports§
Modules§
- image
- math
- Centralized 3D math utilities using ultraviolet internally. All public APIs use standard Rust arrays to hide implementation details.
- text
Structs§
- Context
- Drawing context for managing render commands.
- Draw
Option - Unified options for drawing images and text.
- Input
Manager - Manages the state of all input devices (keyboard, mouse, touch, sensors).
- OneShot
Splash - A reusable startup splash scene with the built-in Spottedcat branding.
- Pt
- A single dimension unit for logical screen positions and sizes.
- Shader
Opts - Uniform options passed to the fragment shader during rendering.
- Sound
Options - Configuration options for playing a sound.
- Touch
Info - Information about a single active touch point.
- Window
Config - Configuration for the application window.
Enums§
- Key
- Represents a physical key on a keyboard.
- Mouse
Button - Represents a button on a mouse or similar pointing device.
- Platform
Event - Events received from the native platform (e.g. Android JNI or iOS ObjC).
- Touch
Phase - Represents the current state of a touch interaction.
Traits§
- Spot
- The core trait for defining application logic and rendering.
Functions§
- compress_
assets - Forces pending asset compression work to run immediately.
- cursor_
position - Alias for
mouse_pos. - delta_
time - Returns the time elapsed since the last frame.
- dt
- Returns the time elapsed since the last frame in seconds.
- fade_
in_ sound - Initiates a fade-in for a playing sound.
- fade_
out_ sound - Initiates a fade-out for a playing sound.
- get_
input - Compatibility alias for
text_input. - get_
registered_ font - Returns a copy of the raw bytes for a registered font.
- get_
resource - Returns a resource of type T from the context, if it exists.
- ime_
preedit - Returns the current IME pre-edit string (uncommitted text).
- insert_
resource - Inserts or replaces a resource of type T in the context.
- is_
background_ transparent - Returns whether the current window background is transparent.
- is_
sound_ playing - Returns true if the sound associated with the play ID is still active.
- key_
down - Returns true if the specified key is currently held down.
- key_
pressed - Returns true if the specified key was just pressed this frame.
- key_
released - Returns true if the specified key was just released this frame.
- load_
asset - Loads an asset from disk or from the platform-specific bundle.
- mouse_
button_ down - Returns true if the specified mouse button is currently held down.
- mouse_
button_ pressed - Returns true if the specified mouse button was just pressed this frame.
- mouse_
button_ pressed_ position - Returns the cursor position if the mouse button was just pressed this frame.
- mouse_
button_ released - Returns true if the specified mouse button was just released this frame.
- mouse_
down - Returns true if the specified mouse button is currently held down.
- mouse_
pos - Returns the current mouse position in logical coordinates.
- mouse_
pressed - Returns true if the specified mouse button was just pressed this frame.
- pause_
sound - Pauses a currently playing sound by its play ID.
- play_
sine - A debug function to play a simple sine wave at the specified frequency.
- play_
sound - Plays a registered sound with the specified options.
- play_
sound_ simple - A convenience function to play a registered sound with default options.
- poll_
platform_ events - Returns a list of raw platform events received this frame.
- pt
- Creates a logical point value (
Pt) from a scalar. - push_
platform_ event - Pushes a custom platform event into the event queue.
- quit
- Signals the engine to quit the application.
- quit_
ctx - Quit helper that keeps the ctx-first API shape.
- register_
font - Registers a TTF/OTF font for text rendering and returns a unique font ID.
- register_
image_ shader - Registers an image shader and returns its shader id.
- register_
shader - Registers a custom WGSL fragment shader extension for image rendering.
- register_
sound - Registers a sound from raw bytes and returns a unique sound ID.
- resume_
sound - Resumes a paused sound by its play ID.
- run
- Starts the application with the specified scene type
Tand configuration. - scale_
factor - Returns the window’s scale factor (DPI).
- set_
background_ transparent - Sets whether the current window background should be transparent.
- set_
cursor_ visible - Requests cursor visibility update.
- set_
fullscreen - Requests fullscreen toggle.
- set_
sound_ volume - Sets the volume of a playing sound directly.
- set_
text_ input_ enabled - Enables or disables text input (IME) for the window.
- set_
window_ size - Sets the window’s logical size.
- set_
window_ title - Requests a window title update.
- stop_
all_ sounds - Stops all currently playing sounds.
- stop_
sound - Stops a playing sound immediately by its play ID.
- switch_
scene - Switches to a new scene of type
T. - switch_
scene_ ctx - Scene switch helper that keeps the ctx-first API shape.
- switch_
scene_ with - Switches to a new scene of type
Tand passes a payload. - switch_
scene_ with_ ctx - Scene switch with payload helper that keeps the ctx-first API shape.
- take_
resource - Removes and returns a resource of type T from the context, if it exists.
- text_
input - Returns the accumulated text input string for the current frame.
- text_
input_ enabled - Returns true if text input (IME) is currently enabled.
- total_
elapsed - Returns total elapsed time since engine start.
- touch_
down - Returns true if any touch point is currently active.
- touches
- Returns a slice of active touch points.
- unregister_
font - unregister_
sound - Unregisters a sound and frees its resources.
- vh
- Returns a percentage of the window height as Pt.
- vw
- Returns a percentage of the window width as Pt.
- window_
size - Returns the window’s logical size as a tuple of
(width, height).