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.
The engine uses a decoupled main loop with a fixed-step update (UPS) for logic and a variable refresh rate (FPS) for rendering, combined with built-in state interpolation for smooth visuals.
§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, screen: Image) {
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]);
screen.draw(ctx, &self.image, 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.
- Gamepad
Id - Stable identifier assigned to a connected gamepad.
- Gamepad
Info - Basic information about a gamepad known to the input system.
- Image
Shader Bindings - Per-draw image shader bindings.
- Image
Shader Desc - High-level description for registering a custom image shader.
- Image
Shader Template - A builder for creating data-driven image shaders with automatic boilerplate injection.
- Input
Manager - Manages the state of all input devices (keyboard, mouse, touch, sensors).
- Model
Shader Template - 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.
- Texture
- Handle to a texture resource.
- Touch
Info - Information about a single active touch point.
- Window
Config - Configuration for the application window.
Enums§
- Gamepad
Axis - Logical gamepad axes exposed by spottedcat.
- Gamepad
Button - Logical gamepad buttons exposed by spottedcat.
- Image
Repeat - Controls how an image is sampled when the drawn quad is larger than one tile.
- Image
Shader Blend Mode - Supported high-level blend modes for image shaders.
- Image
Shader Input - Optional per-draw bindings for custom image shaders.
- 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§
- Drawable
- Trait for objects that can be drawn into an
Image. - Spot
- The core trait for defining application logic and rendering.
Functions§
- 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.
- gamepad_
axis - Returns the current value of a gamepad axis, or 0.0 if unavailable.
- gamepad_
button_ down - Returns true if the specified gamepad button is currently held down.
- gamepad_
button_ pressed - Returns true if the specified gamepad button was just pressed this frame.
- gamepad_
button_ released - Returns true if the specified gamepad button was just released this frame.
- gamepad_
connected - Returns true if the gamepad is currently connected.
- gamepads
- Returns basic information for every gamepad known to the input system.
- 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.
- image_
shader_ template - Returns a full WGSL image shader template that matches Spot’s current image pipeline contract.
- 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.
- model_
shader_ template - Returns a full WGSL model shader template that matches Spot’s current 3D pipeline contract.
- 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.
- mouse_
released - Returns true if the specified mouse button was just released 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.
- rebuild_
assets - Forces pending asset rebuild/re-upload to GPU to run immediately.
- register_
font - Registers a TTF/OTF font for text rendering and returns a unique font ID.
- register_
image_ shader_ desc - Registers a custom image shader using the descriptor API.
- register_
image_ shader_ template - Registers an image shader generated from the template API.
- 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).
- scroll_
delta - Returns the current frame’s scroll wheel delta.
- 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).