Skip to main content

Crate repame_sprite

Crate repame_sprite 

Source
Expand description

2D sprite viewport: snapshot in, pixels out.

The UI builds a FrameInput per frame (plain data, rebuilt during composition) and mounts Viewport2d as a Repose view, which draws the snapshot through a dp-space FitMode and reports pointer picks back in world coords. Unit discipline lives here, once: games work in world/dp units and do not touch physical px. Camera state lives in Repose signals, not in the renderer.

Re-exports§

pub use batch::AtlasUpload;
pub use batch::BatchDesc;
pub use batch::SpriteBatch;
pub use batch::TextureFilter;
pub use batch::draw_batch;
pub use batch::draw_batch_with_id;
pub use batch::frame_uv;
pub use batch::instance_rows;
pub use batch::screen_camera;
pub use batch::sprite_aabb;
pub use fullscreen::FullscreenDesc;
pub use fullscreen::FullscreenPass;
pub use fullscreen::FullscreenTexture;
pub use fullscreen::FullscreenTextureRef;
pub use fullscreen::FullscreenTextureUpload;
pub use sprite_image::SpriteImage;
pub use sprite_image::SpriteImageAsset;
pub use sprite_image::SpriteImageDef;
pub use sprite_image::SpriteImageError;
pub use sprite_image::SpriteImageFrameDef;

Modules§

batch
GPU sprite batch: instanced textured quads as a WgpuCallback. Owns the atlas texture array and instance buffer. Feeds from AtlasUploads, draws through a caller-supplied camera matrix.
fullscreen
Fullscreen procedural passes: game-specific WGSL over a generated triangle, with engine-owned pipeline/uniform/texture management.
post
Post-process composite for the GPU viewport: scene renders into an offscreen texture, then a fullscreen pass grades it back to the screen. (Bevy post_process analog: NT’s screen_effects.wgsl sampled the view target; in-pass callbacks cannot, so the viewport owns the intermediate.)
sprite_image

Structs§

Camera2d
2D orthographic camera. Owned by the UI (signals), copied into the snapshot per frame. effective_center is center + offset. Canvas, GPU batch, and picks derive from these fields together.
CursorFrame
One decoded + magnified hardware-cursor frame.
FrameGeom
One painted frame’s geometry, shared between viewports (writers) and world-anchored siblings such as ActorFrame (readers). Maps either direction so board sprites, picks, and actor surfaces track together, including under camera shake.
FrameInput
Everything the viewport draws this frame. Plain snapshot data.
GeomHandle
Shared paint-time geometry. Canvas views use this on the UI thread; GPU callbacks hold it behind a mutex (Send + Sync).
SpriteInstance
One batched sprite. uv is in atlas texels normalized to 0..1.
WorldText
World-anchored text floater (damage numbers, +25).

Enums§

FitMode
How the world rect is framed when the canvas aspect differs from world_size. Named like Godot’s `Window.stretch/aspect.
PickEvent
UI-facing pointer events from the viewport. Click fires on pointer up when the press started inside and the pointer stayed within slop. Press is the down-edge.
SpriteBlend
Blend mode per sprite. Additive uses SrcAlpha + One. Sorted into ranges (alpha, then multiply, then additive): push order across blend modes is NOT preserved, see the batch module docs.

Constants§

CLICK_SLOP_DP
Press slop in dp: pointer-up farther than this from pointer-down cancels the Click (drag-off-cancel). Density-independent: compared after dividing physical-px deltas by the painted density, so a tap cancels identically on density 1 and density 3.
CLICK_SLOP_PX
Legacy physical-px slop value. Kept so old call sites keep compiling; new code uses CLICK_SLOP_DP via click_within_slop_dp.

Functions§

ActorFrame
World-anchored surface: child is boxed to a size rect centered on a world center, positioned through FrameGeom. mirror_x flips about the surface center (rozvp horde case: centered content). Offsets trail the board by one frame under camera motion; steady state matches. For origin-bearing art (NT sprites with off-center xorigin/yorigin), prefer ActorFrameWithOrigin or the sprite batch’s anchor flips, which mirror about the anchor instead.
ActorFrameWithOrigin
Origin-aware ActorFrame: mirror_x flips about the normalized origin ([0, 1], e.g. an NT xorigin / w) instead of the surface center. Set origin from the catalog’s AnimDef::anchor when the surface content carries an off-center sprite origin.
Viewport2d
2D viewport view. Gesture handling and camera state live in the FrameInput snapshot. Fills its parent; draws background, then sprites, then world texts, then the fullscreen tint. Each paint publishes FrameGeom to geom_out for dp-space siblings.
Viewport2dGpu
GPU twin of Viewport2d: same snapshot in, same picks out, with sprites as textured atlas quads through SpriteBatch. Fills its parent. background paints first and overlay_color last, matching canvas except world texts, which stay canvas-side as sibling views.
Viewport2dGpuWithHud
Stack GPU sprites under canvas texts/tint from one FrameInput. Mounts Viewport2dGpu plus a transparent canvas pass for texts / overlay_color, so GPU games keep damage numbers and tints.
Viewport2dGpuWithHudShared
Viewport2dGpuWithId
GPU viewport with explicit batch id so a second viewport or minimap can coexist (each id owns its pipeline and instances).
Viewport2dGpuWithIdShared
Viewport2dShared
aim_world
Continuous-aim inverse: like pick_world but through an unshaken camera (offset and trauma roll zeroed). Picks must track the painted view; aim must not inherit shake jitter. Pass the same world_size and density the viewport painted with, plus the look point and roll of the camera without shake applied.
aim_world_unshaken
aim_world straight from a Camera2d: uses the follow target (center, no shake offset) with zero roll so firing aim never sprays with the noise function. Paint the viewport with the shaken camera; read aim with this.
click_within_slop_dp
Dp-space slop check: physical-px points divided by density (falling back to 1.0) before comparing against CLICK_SLOP_DP.
contain_fit
Contain-fit of a world extent into a dp-space canvas: uniform scale plus centering offsets. world_to_dp / dp_to_world invert each other for any positive scale.
cursor_frame
dp_to_world
Inverse of world_to_dp. Degenerate scales return the look point.
dp_to_world_with_roll
Inverse of world_to_dp_with_roll.
effective_fit
Effective fit for one frame: base contain-fit scaled by zoom / units_per_pixel, re-centered. Default camera matches contain_fit; zoom 2 doubles on-screen size on both backends.
fit_view_proj
GPU camera for the shared framing contract: matrix form of world_to_dp over canvas_dp (dp = physical px / density).
fit_view_proj_with_roll
fit_view_proj plus camera roll about the look point. 0.0 matches fit_view_proj.
pick_world
Viewport-local physical-px press to world point through the painted FrameGeom. Takes the region-local position, so HUD chrome or a non-fullscreen viewport does not shift picks.
surface_dp
World-anchored surface rect in dp: ([off_x, off_y], [w, h]). ActorFrame is its view form. The center rotates with roll about the pivot; size stays axis-aligned.
unproject_px
Unproject one window-physical px point through this frame’s camera.
world_to_dp
World point to dp canvas point through the fit. At the default center (world / 2) this is offset + world * scale.
world_to_dp_with_roll
world_to_dp plus camera roll around cam_center.