Skip to main content

SSPlayer

Struct SSPlayer 

Source
pub struct SSPlayer { /* private fields */ }
Expand description

The SpriteStudio player. One instance owns one animation-instance tree.

Implementations§

Source§

impl SSPlayer

Source

pub fn new() -> Self

Create a player. Takes nothing: a player holds no GPU resource at all, which is what makes putting a hundred of them in a scene cheap. The device-scoped SSRenderer and the target-scoped SSScene are lent to it per frame by SSScene::update.

Source

pub fn restore_textures( &mut self, renderer: &mut SSRenderer, device: &Device, queue: &Queue, )

Re-offer this player’s embedded atlases after a device loss.

The player itself has nothing to rebuild — it owns no GPU resource. What it does own is the .ssab, which is the only place a Retention::Reproducible texture can come back from, so the host calls this once per player after SSRenderer::restore_device and SSScene::restore_device.

Playback state (packs, the instance tree, the current frame) is CPU-side and was never affected: the animation resumes where it was interrupted.

Source

pub async fn load_with( &mut self, loader: &mut impl AssetLoader, src: &str, ) -> Result<(), SSRuntimeError>

Load a .ssab and everything it depends on, then select it.

One call is the whole of loading: the pack, both of its texture tables in either export mode, and — transitively — the sibling packs its instance parts play from, with their textures. Nothing is left for the caller to discover and fetch by hand, which is the point: a host that has to walk textures() itself will sooner or later miss external_textures() and ship white silhouettes.

src is where the pack is, in whatever terms loader understands — a path for SSPlayer::load, a URL for the web face. Everything the pack names is resolved against its directory, because that is what the exporter wrote the paths relative to; the walk never joins those paths itself, it hands src to AssetLoader::set_base once and asks for bare names after that.

A pack keeps the name inside the .ssab. That is the name instance references are matched against (ref_anime_pack), and the same string is the sibling file’s stem, which is what makes those siblings findable at all. Use SSPlayer::load_ssab to name a pack yourself, and expect external references to it to stop resolving.

Only the pack itself is worth an error: everything else is reported through AssetLoader::warn and skipped, so one unreadable atlas does not cost you the character.

SSPlayer::load is this call with the filesystem plugged in; reach for this one when the bytes live somewhere a File::open cannot reach — a .pck, an APK, an engine’s asset server, a URL.

Source

pub fn load(&mut self, path: impl AsRef<Path>) -> Result<(), SSRuntimeError>

Load a .ssab off the filesystem and everything it depends on, then select it.

The whole of loading, in one call and with no wgpu state in sight:

let mut player = SSPlayer::new();
player.load("assets/overall/Instance.ssab")?;
player.set_animation("anime_1")?;
player.play();

It borrows no Device or Queue because the borrow model lends none until the frame starts: what it reads is decoded and uploaded by the first SSScene::update, on exactly the timeline an embedded atlas already takes. So nothing is on the GPU when this returns, and nothing needs to be.

path is resolved by the process’s working directory; everything the pack names — its atlases, the sibling packs its instance parts play from — is resolved against the .ssab’s own directory, because that is what the exporter wrote those paths relative to. That directory is Path::parent’s answer, so the platform decides it rather than us.

Use SSPlayer::load_with where a File::open cannot reach the bytes: a Godot .pck, an APK, an engine’s asset server, a browser.

Source

pub async fn load_assets( &mut self, loader: &mut impl AssetLoader, pack_name: &str, )

The half of SSPlayer::load that runs on an already registered pack: its atlases, and the packs it plays from, transitively.

For a host that got the bytes some other way — a drop, a bundler, an archive — and registered them with SSPlayer::load_ssab.

loader must already be rooted where the pack’s relative paths resolve, because this entry point has no src to hand AssetLoader::set_base: the bytes came from somewhere it never saw. Everything asked for here is a bare name — an atlas path as the exporter wrote it, or <pack>.ssab.

Source

pub fn missing_assets(&self) -> &[MissingAsset]

What the last load could not get, in the order it gave up. Empty means everything the packs asked for arrived.

A load reports Err only when the .ssab itself is unreadable, because one missing atlas must not cost you the character. This is how a caller tells “complete” from “played anyway”: check it right after load, and decide for itself whether a silhouette is worth failing over.

player.load("assets/overall/Instance.ssab")?; // the pack was readable …
for missing in player.missing_assets() { // … but maybe not all of it
eprintln!("{:?} {} is not there", missing.kind, missing.name);
}

Reset by every SSPlayer::load_with and SSPlayer::set_pack (SSPlayer::load_ssab included), so it always describes the most recent load rather than the player’s history.

Source

pub fn has_pack(&self, name: &str) -> bool

Whether a pack is registered under name — what an instance part’s ref_anime_pack will be looked up by.

For a host resolving those references itself: it answers “have I already fetched this one”, which is what keeps a cycle of packs referencing each other from being walked forever.

Source

pub fn add_pack(&mut self, pack: &SSPack)

Register a pack for external instance references without changing what is playing. Registration is by SSPack::name.

Sharing one pack between players is the intended shape: the clone is an Arc bump, and the atlas reaches the GPU once no matter how many players hold it.

Re-registering a name a live animation is playing from does not change what is playing: the tree keeps the resource it was built from until the next SSPlayer::set_animation, because its Contexts point at that resource directly (see retired).

Source

pub fn set_pack(&mut self, pack: &SSPack)

Register pack and make it the one SSPlayer::set_animation selects from. Clears the current animation.

Source

pub fn add_ssab( &mut self, pack_name: &str, data: &[u8], ) -> Result<(), SSRuntimeError>

Parse data and register it under pack_name — SSPack::load_named + SSPlayer::add_pack in one call, for hosts holding bytes rather than packs (the C and js faces, and anything naming packs after files).

Source

pub fn load_ssab( &mut self, pack_name: &str, data: &[u8], ) -> Result<(), SSRuntimeError>

SSPlayer::add_ssab + SSPlayer::set_pack: register pack_name and make it the main pack to play from.

Source

pub fn set_animation(&mut self, anim_name: &str) -> Result<(), SSRuntimeError>

Select the animation to play, (re)building the instance tree. The tree is left at its start frame and not playing — call SSPlayer::play.

This is the allocating half of playback (contexts, slots, mask flags), so the start/stop calls below can stay allocation-free. Mirrors the runtime’s own setup_animation + play split.

Source

pub fn play_from(&mut self, start_frame: f32)

SSPlayer::play from start_frame rather than from the head of the section. The family spells this play(startFrame); Rust has no overloads, so it is a second name here.

Not a resume either — it re-arms the loop count exactly as play does, and the frame it starts from becomes the reference the loop counts from. A frame outside the section is brought inside it, as SSPlayer::seek does; a negative one starts from the head, as play does.

Source

pub fn play(&mut self)

Start the selected animation from the head of its section, re-arming the loop count. Not a resume: it rewinds, so lifting a SSPlayer::pause is SSPlayer::resume’s job. No-op until SSPlayer::set_animation has succeeded.

Source

pub fn pause(&mut self)

Hold playback on the current frame. Idempotent, and ignored while nothing is playing. SSPlayer::is_playing stays true — a hold is not a stop.

Source

pub fn resume(&mut self)

Lift a SSPlayer::pause, carrying on from the same frame. Idempotent, and a no-op on a stopped animation — starting one is SSPlayer::play’s job, and it rewinds.

Source

pub fn stop(&mut self)

End playback. The playhead stays where it stands; nothing rewinds, so the host keeps drawing the frame it stopped on.

Source

pub fn set_speed_scale(&mut self, speed: f32)

Scale playback by speed, a multiple of the frame rate. 0.0 and negatives are a stop, not reverse playback – that is SSPlayer::set_playback_direction – and read back from SSPlayer::speed_scale as the 0.0 they became.

Survives SSPlayer::set_animation and a pack change, and may be set before the first animation.

Source

pub fn speed_scale(&self) -> f32

The speed in effect, as a multiple of the frame rate. Read from the runtime, so a rate that clamped to a stop reads back as 0.0 rather than as the negative that was asked for.

Source

pub fn is_playing(&self) -> bool

Whether an animation has been started and has neither stopped nor finished. A SSPlayer::pause leaves it true; SSPlayer::is_pausing says whether it is held.

Source

pub fn is_pausing(&self) -> bool

Held in place rather than stopped: SSPlayer::is_playing stays true. False before the first SSPlayer::play and after SSPlayer::stop — the runtime keeps “paused” implying “playing”.

Source

pub fn is_playing_forward(&self) -> bool

Which way the playhead is actually travelling, which is not the heading SSPlayer::set_playback_direction configured: under ping-pong the return leg runs backward while SSPlayer::playback_direction still reads forward. A negative speed does not flip it either — that is a stop.

This is the gate to put in front of audio. SpriteStudio has no reverse audio, so an crate::SsEvent::Audio crossed on a backward leg is not meant to sound; the sibling players that own an audio stack apply exactly this test before playing one.

True with no animation set up: forward is the resting state, and reporting backward would gate a host’s audio off on its first frame.

Source

pub fn is_finished(&self) -> bool

Every configured loop has played. Sticky until the next play or switch of track 0’s animation (SSPlayer::set_animation, or a crossfade or track animation on track 0), and never true under an infinite loop.

Source

pub fn seek(&mut self, frame: f32)

Jump to frame. Fractional values are honoured — the tree is evaluated at the sub-frame position on the next update.

Source

pub fn frame_no(&self) -> f32

Current playhead position, fractional. Zero before an animation is set.

Source

pub fn start_frame(&self) -> i32

First and last frame of the range being played, and its length (end - start + 1, both ends inclusive). All zero before an animation is set. These follow SSPlayer::set_animation_section, so they describe what the transport actually walks rather than what the pack contains.

Source

pub fn end_frame(&self) -> i32

Source

pub fn total_frames(&self) -> i32

Source

pub fn set_loop_count(&mut self, count: i32)

count cycles then stop; -1 (or 0) loops forever. Under PlaybackStyle::PingPong one cycle is a full round trip.

Source

pub fn loop_count(&self) -> i32

The configured count — before an animation is set up, the one SSPlayer::set_loop_count is holding for it, or 0 when none was set.

Source

pub fn remaining_loops(&self) -> i32

How many cycles of SSPlayer::loop_count are left; 0 with no animation.

Source

pub fn set_frame_rate(&mut self, fps: i32)

Override the advance rate. The pack’s authored rate otherwise, and 0 or below goes back to it — prefer SSPlayer::set_speed_scale, which scales playback without replacing it.

Survives SSPlayer::set_animation and a pack change, and may be set before the first animation.

Source

pub fn frame_rate(&self) -> i32

See SSPlayer::set_frame_rate. Before an animation is set, the override, or zero without one.

Source

pub fn set_animation_section( &mut self, start: i32, end: i32, ) -> Result<(), SSRuntimeError>

Restrict playback to start..=end of the current animation, so looping and ping-pong turn around inside that range. Reflected by SSPlayer::start_frame / SSPlayer::end_frame.

Both ends are included, so start == end holds that one frame. An end outside the animation (-1, say) stands for the animation’s edge on that side. An end before the start, both inside the animation, is refused with SSRuntimeError::InvalidParameter, and the section and the playhead stay as they were.

Call it after SSPlayer::set_animation: frame numbers only mean something inside the animation they were measured in, and setting an animation rebuilds the tree and takes the section with it.

Source

pub fn set_track_animation( &mut self, track: u32, anim_name: &str, ) -> Result<(), SSRuntimeError>

Put anim_name on track, replacing what it was playing. Track 0 is better set with SSPlayer::set_animation, which rebuilds the instance tree; this is for the overlay tracks above it. On track 0 it still makes anim_name the SSPlayer::current_animation.

Source

pub fn set_track_alpha( &mut self, track: u32, alpha: f32, ) -> Result<(), SSRuntimeError>

How much of track survives onto the pose the tracks below it produced.

Source

pub fn track_alpha(&self, track: u32) -> Option<f32>

track’s alpha, or None when no animation is set up or there is no such track.

Source

pub fn set_track_blend( &mut self, track: u32, blend: TrackBlend, ) -> Result<(), SSRuntimeError>

TrackBlend::Mix lerps toward the track’s pose; TrackBlend::Additive adds its offset from the setup pose, leaving what is below showing through.

Source

pub fn track_blend(&self, track: u32) -> Option<TrackBlend>

How track composes onto the tracks below it, or None when there is no such track.

Source

pub fn set_track_sync( &mut self, track: u32, sync: TrackSync, ) -> Result<(), SSRuntimeError>

Where the animations laid on track start: TrackSync::Free from the head of their section, TrackSync::Start at the phase track 0 stands at, so a run laid over a walk keeps its stride. Set it before laying; SSPlayer::set_animation resets every track to Free.

Source

pub fn track_sync(&self, track: u32) -> Option<TrackSync>

Where the animations laid on track start (see SSPlayer::set_track_sync), or None when there is no such track.

Source

pub fn track_count(&self) -> u32

How many tracks are laid, track 0 included. Zero when no animation is set up.

Source

pub fn clear_track(&mut self, track: u32) -> Result<(), SSRuntimeError>

Silence a track. Track 0 is refused — fade it to alpha 0 instead.

Source

pub fn crossfade( &mut self, track: u32, anim_name: &str, duration_ms: f32, ) -> Result<(), SSRuntimeError>

Fade track to anim_name over duration_ms, starting from whatever it is playing. Advanced by SSScene::update.

On track 0, anim_name takes over from the call on, not when the fade completes: it is the SSPlayer::current_animation, its state is what SSPlayer::is_finished and the frame read-outs report, and it plays with the speed, direction and loop count the host set. The instance tree is not rebuilt the way SSPlayer::set_animation rebuilds it; the instance and effect parts belong to the pack, so the running children carry on under the new animation’s keys.

Source

pub fn fade_track( &mut self, track: u32, target: f32, duration_ms: f32, ) -> Result<(), SSRuntimeError>

Drive track’s alpha to target over duration_ms. Fading track 0 to 0 settles the pose onto the setup pose.

Source

pub fn track_fade_progress(&self, track: u32) -> Option<f32>

Progress of the fade in flight on track, from 0 to 1, or None when it is not fading.

Source

pub fn cancel_track_fade(&mut self, track: u32) -> Result<(), SSRuntimeError>

Cancel track’s fade, leaving its alpha and weights where they stand.

Source

pub fn set_track_frame( &mut self, track: u32, frame: f32, ) -> Result<(), SSRuntimeError>

Seek a track’s animation — how a continuous-control axis is driven: author it as an animation and scrub it with the tracked value.

Source

pub fn track_frame(&self, track: u32) -> Option<f32>

track’s playhead, or None when there is no such track.

Source

pub fn set_track_speed( &mut self, track: u32, speed: f32, ) -> Result<(), SSRuntimeError>

Set track’s speed, as a multiple of each animation’s frame rate. Track 0’s is SSPlayer::set_speed_scale.

Source

pub fn track_speed(&self, track: u32) -> Option<f32>

What SSPlayer::set_track_speed stored; a negative speed reads back as the 0.0 it became.

Source

pub fn set_track_frame_rate( &mut self, track: u32, fps: i32, ) -> Result<(), SSRuntimeError>

SSPlayer::set_frame_rate for one track.

Source

pub fn track_frame_rate(&self, track: u32) -> Option<i32>

The rate the track’s animation plays at: the override, or the authored rate. Some(0) for a track with neither.

Source

pub fn set_track_frame_skip_enabled( &mut self, track: u32, skip: bool, ) -> Result<(), SSRuntimeError>

Source

pub fn track_frame_skip_enabled(&self, track: u32) -> Option<bool>

Whether track skips frames to keep time, or None when there is no such track.

Source

pub fn set_track_playback_direction( &mut self, track: u32, direction: PlaybackDirection, style: PlaybackStyle, ) -> Result<(), SSRuntimeError>

Source

pub fn track_playback_direction(&self, track: u32) -> Option<PlaybackDirection>

Which way track’s playhead walks, or None when there is no such track.

Source

pub fn track_playback_style(&self, track: u32) -> Option<PlaybackStyle>

How track behaves at the end of its section, or None when there is no such track.

Source

pub fn set_track_loop_count( &mut self, track: u32, count: i32, ) -> Result<(), SSRuntimeError>

How many times the track’s animation plays before it holds its last frame; -1 (or 0) loops forever. Set it after laying the animation: an animation is laid looping forever. On track 0 this is SSPlayer::set_loop_count: the player keeps the count and puts it back on every animation laid there.

Source

pub fn track_loop_count(&self, track: u32) -> Option<i32>

-1 for a track that loops forever; None for one with no animation.

Source

pub fn is_track_finished(&self, track: u32) -> bool

The track’s animation has played its loop count out and holds its last frame, still mixed in until the host fades or clears the track. A state, as SSPlayer::is_finished is for track 0; there is no edge for it.

Source

pub fn track_just_looped(&self, track: u32) -> bool

The last update wrapped the track’s animation back to its start, as SSPlayer::just_looped is for track 0, and like it false after a culled update.

Source

pub fn set_track_outgoing_event_threshold( &mut self, track: u32, threshold: f32, ) -> Result<(), SSRuntimeError>

How far into a crossfade on track the outgoing animation keeps firing events: while its share of the track, 1 - progress, is at least threshold. The default, +∞, silences it from the moment the fade begins, when the incoming one starts firing; 0.5 keeps it firing for the first half. Kept by the track, so it holds for every crossfade on it. The update that completes the fade has already released the outgoing animation, so it fires nothing there, even at 0.

Source

pub fn track_outgoing_event_threshold(&self, track: u32) -> Option<f32>

The threshold the outgoing side of a crossfade on track fires its events at, or None when there is no such track.

Source

pub fn track_main_source(&self, track: u32) -> Option<u32>

The source carrying track’s animation — the one set_track_animation, crossfade or set_animation put there.

Source

pub fn add_track_source( &mut self, track: u32, anim_name: &str, weight: f32, ) -> Result<u32, SSRuntimeError>

Lay anim_name on track beside what it already carries, at weight, and return its handle. On an empty track it becomes the main source. It starts per the track’s TrackSync.

Source

pub fn set_source_weight( &mut self, source: u32, weight: f32, ) -> Result<(), SSRuntimeError>

A source’s share within its track: weights are ratios, so (0.7, 0.3) and (7, 3) mix alike. The track’s strength is SSPlayer::set_track_alpha.

Source

pub fn source_weight(&self, source: u32) -> Option<f32>

source’s weight within its track, or None when there is no such source.

Source

pub fn set_source_frame( &mut self, source: u32, frame: f32, ) -> Result<(), SSRuntimeError>

Seek one source. Sources of different lengths drift apart; this is how a host keeps them in step.

Source

pub fn source_frame(&self, source: u32) -> Option<f32>

source’s playhead, or None when there is no such source.

Source

pub fn set_source_event_threshold( &mut self, source: u32, threshold: f32, ) -> Result<(), SSRuntimeError>

The weight at or above which source fires its events. Only track 0’s main source fires by default (the default threshold is +∞); lower this to the source’s weight or below to have it fire too.

Source

pub fn source_event_threshold(&self, source: u32) -> Option<f32>

The weight source must reach for its events to fire, or None when there is no such source.

Source

pub fn set_playback_direction( &mut self, direction: PlaybackDirection, style: PlaybackStyle, )

Which way the playhead walks, and what it does at the far end. Taken together because the runtime sets them as a pair — pass the current value for whichever you are not changing.

Survives SSPlayer::set_animation and a pack change, and may be set before the first animation.

Source

pub fn playback_direction(&self) -> PlaybackDirection

Source

pub fn playback_style(&self) -> PlaybackStyle

Source

pub fn set_sub_frame_enabled(&mut self, enabled: bool)

Whether the frame handed to the runtime for display keeps its fraction. On by default here.

The playhead is an f32 either way — SSPlayer::frame_no reports it unrounded, and the instance / effect slots are always stepped from the unrounded value, because truncating there would freeze a child whenever a tick is worth less than a frame. Turning this off only floors what is drawn, which is what pins playback to whole authored frames.

Distinct from SSPlayer::set_frame_skip_enabled, which is about time: skip frames decides whether a long tick catches up or advances one frame; this decides whether what is drawn may sit between two of them.

Source

pub fn sub_frame_enabled(&self) -> bool

Source

pub fn set_frame_skip_enabled(&mut self, skip: bool)

How a long tick is spent. On (the default) advances by the elapsed time and drops the frames in between, keeping playback on the wall clock; off advances exactly one frame per update, so nothing is skipped but a stalled host plays in slow motion.

Survives SSPlayer::set_animation and a pack change, and may be set before the first animation.

Source

pub fn frame_skip_enabled(&self) -> bool

Source

pub fn find_part_index(&self, name: &str) -> Option<u32>

Resolve a part name to its index in the current animation, or None when the name is unknown or no animation is set up.

Only worth calling to cache the index across many frames — every override below takes the name directly and resolves it for you.

Source

pub fn set_part_visibility_override( &mut self, part: &str, hide: bool, cascade: bool, ) -> Result<(), SSRuntimeError>

Force-hide a part, or revert it to the animation.

cascade propagates a force-hide to the part’s descendants. A keyframe hide never cascades, so this is the only way to hide a whole sub-tree. Visibility has no priority mode: it always beats the keyframe, and is always cleared when a new animation is set up.

Errors with InvalidParameter when the name is not in the current animation. Take SSPlayer::set_part_visibility_override_by_index when you already hold the index.

Source

pub fn set_part_visibility_override_by_index( &mut self, part: u32, hide: bool, cascade: bool, ) -> Result<(), SSRuntimeError>

Source

pub fn clear_part_visibility_override( &mut self, part: &str, ) -> Result<(), SSRuntimeError>

Revert a part to the animation’s own visibility.

Source

pub fn clear_part_visibility_override_by_index( &mut self, part: u32, ) -> Result<(), SSRuntimeError>

Source

pub fn set_part_color_override( &mut self, part: &str, rgba: u32, blend_op: BlendOp, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Override a part’s colour with one value across all four corners.

rgba is packed 0xRRGGBBAA in the same 8-bit sRGB space as the authored PartColor: the runtime multiplies its alpha with the part’s composed alpha itself, so do not pre-multiply or gamma-convert it here. That alpha is also the strength, which is why BlendOp::Mix is the plain case and the value to pass when you have no reason to pass another.

Normal parts only. Others ignore it silently — Ok means the override was recorded, not that anything looks different.

Source

pub fn set_part_color_override_by_index( &mut self, part: u32, rgba: u32, blend_op: BlendOp, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Source

pub fn set_part_color_override_corners( &mut self, part: &str, corners: [[u8; 4]; 4], blend_op: BlendOp, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Override a part’s colour with four distinct corners, for a gradient.

Same contract as SSPlayer::set_part_color_override. corners is in the runtime’s order — left-top, right-top, left-bottom, right-bottom, each [r, g, b, a] — and getting that order wrong flips the gradient silently rather than failing. One argument rather than four, so the pair of colour methods reads the same.

Source

pub fn set_part_color_override_corners_by_index( &mut self, part: u32, corners: [[u8; 4]; 4], blend_op: BlendOp, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Source

pub fn clear_part_color_override( &mut self, part: &str, ) -> Result<(), SSRuntimeError>

Revert a part to the animation’s own colour. Clears either kind of colour override — they share one slot per part.

Source

pub fn clear_part_color_override_by_index( &mut self, part: u32, ) -> Result<(), SSRuntimeError>

Source

pub fn set_part_cell_override( &mut self, part: &str, cellmap_name: &str, cell_name: &str, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Make a part draw a different cell.

cellmap_name is written without the .ssce extension. Both names are hashed here, so pass them exactly as they appear in the pack — see SSPlayer::cellmap_names and SSPlayer::cell_names for what is available. Normal and Mask parts only; errors when the cell cannot be resolved against the bound .ssab.

Source

pub fn set_part_cell_override_by_index( &mut self, part: u32, cellmap_name: &str, cell_name: &str, priority: OverridePriority, ) -> Result<(), SSRuntimeError>

Source

pub fn clear_part_cell_override( &mut self, part: &str, ) -> Result<(), SSRuntimeError>

Revert a part to the animation’s own cell.

Source

pub fn clear_part_cell_override_by_index( &mut self, part: u32, ) -> Result<(), SSRuntimeError>

Source

pub fn clear_all_part_overrides(&mut self)

Drop every override on the root animation at once.

Source

pub fn just_started(&self) -> bool

Whether the last update was the first to run after a SSPlayer::play or SSPlayer::play_from — the start edge, true for exactly one update.

Not raised by SSPlayer::resume: lifting a pause carries on, it does not start. The tick reports it rather than the call, so a play on a culled player is reported by the first tick that runs once it is unculled, and a play that SSPlayer::stop or SSPlayer::set_animation overtook before any tick ran is not reported.

After a play of your own the call site already knows. This is for a start something else made — a declarative binding that plays whatever animation it is handed, as the Bevy adapter does.

Source

pub fn just_looped(&self) -> bool

Whether the last update crossed a loop boundary.

One report per update however many cycles were crossed, since a long tick under frame skipping can complete several. Use it for “the walk cycle came round”; use SSPlayer::just_finished for “the animation is over”.

Source

pub fn just_finished(&self) -> bool

Whether the last update completed playback: the rising edge of the runtime’s sticky finished state, so it reads true for exactly one update.

Never true under an infinite loop, and not raised by SSPlayer::stop — it means “every configured cycle has played”, not “playback is no longer running”. Counting loops, or calling stop yourself, is how you end an infinite one.

Do not derive completion from !is_playing or from reaching the last frame: stop clears the one, and reverse and ping-pong playback pass the other without finishing.

Source

pub fn events(&self) -> &[SsEvent]

Timeline events the last update crossed, in the order the runtime reported the frames carrying them.

Frames skipped over are still represented. The runtime records every frame it stepped through, so a footstep on a frame that a slow tick jumped past still appears here — which it would not if the host looked only at the frame that was landed on.

Empty on a tick that crossed nothing, and on a culled player, which does not advance at all. A player that is merely not visible still advances, so it reports its events as usual.

Source

pub fn part_count(&self) -> usize

How many parts the root animation has. Zero before one is set up.

Derived from the world-matrix buffer, which carries one 4x4 per part, so it is exactly the bound SSPlayer::part_transform checks against.

Source

pub fn part_transform(&self, part: &str) -> Option<[f32; 6]>

The part’s transform on the current frame, as the 2D affine [m00, m01, m10, m11, tx, ty] — the same six numbers, in the same order, that ssplayer-webgl’s getPartTransform returns. A point maps as x' = m00·x + m01·y + tx, y' = m10·x + m11·y + ty.

The space is animation-local and Y-down: this is the part’s pose inside its own animation, with neither SSPlayer::set_transform nor the scene’s projection applied. A host pinning something to a part composes those itself, which is also what lets it pin into whatever coordinate system it actually uses.

None when no animation is set up or part is out of range. Copied out, so unlike a FrameView it is safe to keep.

Read it after SSScene::update — it describes the frame the last update produced. The matrix is computed for every part whether or not it is hidden, so a hidden part still reports where it would have been.

Source

pub fn part_transform_by_index(&self, part: u32) -> Option<[f32; 6]>

Index form of SSPlayer::part_transform, for a caller that already resolved the name and reads the pose every frame.

Source

pub fn is_part_hidden(&self, part: &str) -> Option<bool>

Whether part is hidden on the frame the last SSScene::update built, or None when no animation is set up or it has no such part.

The companion to SSPlayer::part_transform, which reports where a part would be whether or not it is drawn, on the same frame. A host following a part with its own scene graph needs both: the pose to place its follower, and this to decide whether to show it.

It reads that frame and builds none, so a read is a lookup however often it is made, and never changes what the next update builds. An override therefore shows from the next update; a read before then reports the frame before it. A player that is not visible still builds its frame every update, so this keeps following the animation; a culled one, like a tick whose frame could not be built, leaves the last frame in place, as SSPlayer::part_transform does. Some(false) until the first update has built a frame.

Source

pub fn is_part_hidden_by_index(&self, part: u32) -> Option<bool>

Index form of SSPlayer::is_part_hidden, for a caller that already resolved the name.

Source

pub fn is_part_skinned_mesh(&self, part: &str) -> Option<bool>

Whether part is a skinned mesh — a mesh part whose vertices are drawn by bone skinning — or None when the pack has no such part.

Why a host wants it. SSPlayer::part_transform reports a part’s own node transform, which for a skinned mesh stays at its setup position (usually near the character root) while the visible vertices are pulled around by their bones. So pinning a follower to a skinned mesh snaps it to the root rather than onto the art. A host offering a “follow this part” picker can use this to warn, or to steer the choice to a null / bone part, which does carry its transform. It does not change what plays — the transform is faithful to the node, this only names when that is not what a follower wants.

A rigid (deform-only) mesh is not skinned and follows correctly, so it reports false, as does every non-mesh part. The test is one bone binding or more, matching the sibling Players’ is_part_skinned_mesh.

Unlike SSPlayer::is_part_hidden, this is a static property of the pack, not a per-frame state, so it reads the .ssab directly.

Source

pub fn is_part_skinned_mesh_by_index(&self, part: u32) -> Option<bool>

Index form of SSPlayer::is_part_skinned_mesh, for a caller that already resolved the name.

Source

pub fn set_transform( &mut self, x: f32, y: f32, scale_x: f32, scale_y: f32, rotation: f32, )

Place this player: translation, scale, then rotation in radians, composed into the root transform of its tree.

y is measured downward from the centre, matching the Y-down space the players and their SSPlayer::part_transform output live in (and ForWeb’s offsetY).

The per-player half of placement: the projection belongs to the render target (SSScene::set_viewport), the placement to the player. It costs nothing extra to draw: the tree walk already composes an arbitrary parent matrix for every instance child, so a non-identity root simply rides along.

Source

pub fn reset_transform(&mut self)

Reset the placement to the identity: centred, unscaled, unrotated.

Source

pub fn set_order(&mut self, order: i32)

Draw order within a scene; lower draws first. Ties keep whatever order the host hands the players over in.

Source

pub fn order(&self) -> i32

This player’s draw order (see SSPlayer::set_order).

Source

pub fn set_visible(&mut self, visible: bool)

Draw nothing when false, while the timeline keeps running: the playhead advances, events, loops and completions are reported, and the part read-outs (SSPlayer::part_transform, SSPlayer::is_part_hidden) follow the animation. Only the geometry is skipped.

This is what visible means on the other Players, so hiding a character for a moment — a blink, a flicker — does not slow its animation down. To stop paying for a character that cannot be seen at all, use SSPlayer::set_culled instead.

Source

pub fn is_visible(&self) -> bool

Whether this player draws (see SSPlayer::set_visible).

Source

pub fn set_culled(&mut self, culled: bool)

Skip this player entirely when true: SSScene::update advances no timeline and produces no geometry, so SSScene::draw records nothing and the player costs nothing. The time spent culled is dropped, not caught up: uncull it and it carries on from where it stopped.

For a host that knows the player cannot be seen — outside the viewport, or scrolled away. Because the timeline stops, it is the wrong tool for an effect: a character blinked with it plays in slow motion. Use SSPlayer::set_visible for that, or SSPlayer::set_alpha for a fade.

Source

pub fn is_culled(&self) -> bool

Whether this player is skipped entirely (see SSPlayer::set_culled).

Source

pub fn set_alpha(&mut self, alpha: f32)

Player-level fade, clamped to 0..=1 and multiplied into every part’s colour alpha. Mask coverage is deliberately unaffected: a faded player clips exactly as it would at full opacity.

Part by part, so where two parts overlap the player is more opaque than alpha; a scene with SSScene::set_group_alpha on fades the player as one layer instead.

Source

pub fn alpha(&self) -> f32

The player-level fade, clamped to 0..=1 (see SSPlayer::set_alpha).

Source

pub fn set_tint(&mut self, rgb: u32)

Player-level tint: 0xRRGGBB, multiplied into every part the player draws — its instance children included, since the whole tree is one player. White (0xFFFFFF, the default) leaves colours untouched.

It lands after the PartsColor blend, which is what makes it a tint on the finished part rather than another term in that formula. Mask coverage is unaffected, exactly as with SSPlayer::set_alpha: a tinted player clips the shape it always did.

Source

pub fn tint(&self) -> u32

The player-level tint as 0xRRGGBB (see SSPlayer::set_tint).

Source

pub fn set_crowd(&mut self, members: &[CrowdMember])

Draw this one playhead at every member’s placement: a crowd of copies that cost one player’s evaluation, one upload of its geometry and one player’s draw calls, however many there are. Empty — the default — draws the player once, where SSPlayer::set_transform put it. Members past MAX_CROWD_MEMBERS are left out.

The members are copied, into a vector this player keeps, so a host that moves its crowd every frame allocates nothing. Everything but placement, alpha and tint is shared: the frame, the animation and its tracks, the overrides, the events (reported once), the masks and the effects — every member’s particles are the same ones. set_order, set_visible, set_culled and the player’s own alpha and tint apply to the crowd as a whole; to hide one member, leave it out.

Each draw is issued once for every member, so members interleave draw by draw: where two overlap, a later part of the first can cover an earlier part of the second. Under MaskBackend::Coverage each member is clipped by its own mask. Under the stencil backend the members’ masks are written together, so they clip correctly only where members do not overlap.

SSPlayer::part_transform stays in the player’s space, without the player’s placement or any member’s: compose a member’s onto it to follow that member.

Source

pub fn crowd(&self) -> &[CrowdMember]

The crowd SSPlayer::set_crowd set, as it is drawn: alpha clamped, tint masked to 0xRRGGBB. Empty when the player draws once.

Source

pub fn current_animation(&self) -> Option<&str>

The animation currently set up, or None before the first SSPlayer::set_animation — and again after a pack registration replaced what the tree was built from, which is what makes the next set_animation rebuild rather than recognise the name as already set up.

Source

pub fn animation_names(&self) -> Option<Vec<String>>

Names of all animations in the main pack, if loaded.

Source

pub fn part_names(&self) -> Option<Vec<String>>

Every part name in the main pack, in part-index order.

None until a pack is bound. This is what turns the part_index an SsEvent carries back into something a human reads, and what fills a part picker; len() is the part count.

Reads the .ssab parts table, which is static for the resource, rather than SSPlayer::part_count — that one is derived from the world-matrix buffer and is zero until an animation has been set up.

A part authored without a name holds its slot as an empty string, so the vector stays index-aligned with part_index.

Source

pub fn cellmap_names(&self) -> Option<Vec<String>>

Every cellmap name in the main pack, without the .ssce extension — the namespace SSPlayer::set_part_cell_override takes.

None until a pack is bound. Reads the .ssab directly rather than the texture list, because a cellmap whose atlas is embedded still has a name.

Source

pub fn cell_names(&self, cellmap_name: &str) -> Option<Vec<String>>

The cell names inside one cellmap, or None when no pack is bound or the cellmap is not in it. The other half of what SSPlayer::set_part_cell_override takes.

Source

pub fn texture_key(&self, pack_name: Option<&str>, slot: u32) -> u32

Where a pack’s cellmap registers in the renderer’s texture map.

TextureRef::slot names a slot inside one .ssab, and two packs from two projects one tool exported can both call theirs spritemap1. The renderer’s map is device-scoped — that is what keeps N players of one pack to one upload — so the player assigns each atlas a key that identifies the image and translates every draw batch through it. This is that translation, and it is what a host supplying its own pixels has to register under:

for texture in player.textures(None).unwrap_or(&[]) {
    let key = player.texture_key(None, texture.slot);
    renderer.upload_texture(device, queue, key, rgba, (1024, 1024), Retention::Retain);
}

A reference-mode atlas of a pack registered without a load (SSPlayer::add_ssab, SSPlayer::add_pack) is keyed by the pack’s name and the path the exporter wrote, so two projects naming their atlas alike never share a key; sibling packs naming one file each upload it. Answers slot itself for a pack this player does not hold.

Source

pub fn textures(&self, pack_name: Option<&str>) -> Option<&[TextureRef]>

The atlases a registered pack asks for, or None if pack_name names no pack this player holds. None selects the main pack.

This is the reference-mode half of texture supply, and it exists because only the .ssab knows where its atlases were exported to: a host calls it straight after SSPlayer::add_ssab / SSPlayer::load_ssab, loads every entry that is not TextureRef::embedded by resolving TextureRef::path against the directory the .ssab came from, and hands the pixels to SSRenderer::upload_texture under SSPlayer::texture_key’s answer for that entry, not under TextureRef::slot. The player never opens a file itself — it has no filesystem on the web face, and on any face the host’s asset system is the one that should own the bytes.

Source

pub fn embedded_images( &self, pack_name: Option<&str>, ) -> Option<Vec<EmbeddedImage<'_>>>

The encoded atlases a registered pack carries, or None if pack_name names no pack this player holds. None selects the main pack.

The embedded-mode counterpart of SSPlayer::textures: there is nothing for the host to fetch, but there is something for it to decode. A host with its own decoder walks this and registers the results, rather than leaving it to the decode the next SSScene::update runs — which needs the embedded feature and only knows how to decode PNG.

Source

pub fn replaceable_cellmap_names( &self, pack_name: Option<&str>, ) -> Option<Vec<String>>

Every cellmap name and external-texture name in a pack, the namespace SSPlayer::set_cellmap_texture takes. None selects the main pack; None return means no such pack is bound.

Both tables, deliberately: a DrawBatch.texture_hash is a cellmap’s name_hash for an ordinary part but a texture file name’s hash for one under an authored TextureChange, so the file names a TCHG can select (common.png and the like, including a cellmap’s own image) are listed too — all of them legitimately replaceable.

Source

pub fn set_cellmap_texture( &mut self, pack_name: Option<&str>, name: &str, rgba: &[u8], width: u32, height: u32, ) -> Result<(), SSRuntimeError>

Replace the texture a cellmap binds, from straight-alpha RGBA8 pixels.

name is a cellmap name (no .ssce) or a texture file name — one of the strings SSPlayer::replaceable_cellmap_names lists; it is hashed here. None selects the main pack. rgba is width * height * 4 bytes and is premultiplied on the way to the GPU, exactly like a loaded atlas.

The replacement should share the original atlas’s size and cell layout: the runtime’s UVs stay in the original cellmap’s pixel space, so a different resolution samples a different region. Pass a part under a TextureChange its authored file name to affect the frames the change is active on — the cellmap name will not, because those frames bind through a different hash.

The pixels reach the GPU on the next update (the borrow model lends no device before then), so the swap is visible from the following frame.

NotLoaded with no pack bound; InvalidParameter for a pack this player does not hold, a name the pack cannot replace, or pixels that do not fill width x height.

The replacement lives in the device-scoped renderer, which the player does not own: restore it with SSPlayer::restore_cellmap_texture and let an update drop it before dropping the player, or it stays registered.

Source

pub fn override_cellmap_texture_key( &mut self, pack_name: Option<&str>, name: &str, ) -> Option<u32>

Redirect a cellmap to its private override key and return that key, without supplying any pixels — for a host that owns the GPU texture itself (an engine adapter, or the web face registering an ImageBitmap). The caller registers a texture under the returned key against the SSRenderer; every draw of this player’s cellmap then resolves to it.

None on an unbound player, for a pack this player does not hold, and for a name that is not one of SSPlayer::replaceable_cellmap_names. The lower half of SSPlayer::set_cellmap_texture, and the seam SSPlayer::restore_cellmap_texture reverses.

Source

pub fn restore_cellmap_texture( &mut self, pack_name: Option<&str>, name: &str, ) -> Option<u32>

Undo a runtime override: point the cellmap back at the shared atlas and retire the private key. Returns the retired key (so a host that registered its own texture under it can drop that too), or None if the cellmap was not overridden. None pack selects the main pack.

The original atlas was never touched, so there is nothing to reload — the redirect back is the whole of it. The private key’s texture is dropped from the renderer on the next update.

Source

pub fn is_cellmap_overridden(&self, pack_name: Option<&str>, name: &str) -> bool

Whether a cellmap currently carries a runtime override. None pack selects the main pack.

Source

pub fn canvas_rect(&self) -> Option<Rect>

The authored canvas of the currently playing animation, as a box in player-local units — what SSPlayer::fit_into fits when the caller supplies no frame of its own.

This is the frame the artist composed in, not a measured bounding box, and the difference is the point: it costs nothing to read, it holds still while the animation plays, and it is where the author decided the empty space belongs. A tighter box is the host’s to supply through Placement::frame — measuring one here would mean baking every frame of the animation at load.

It is the current animation’s canvas, and one pack’s animations may differ (Ringo’s dead is 1300 wide, its others 800), so a host that wants one scale across a switch reads this once, after its first SSPlayer::set_animation, and passes it as Placement::frame from then on.

The canvas is placed against the origin by the animation’s pivot, which the runtime does not apply (it carries no pivot in its metadata) and which is normalised from the canvas centre: (0, -0.5) is the bottom edge, so a character authored standing on the ground reports a box entirely above the origin — negative y, because player-local y runs downward.

Source

pub fn fit_into( &mut self, width: f32, height: f32, placement: &Placement, ) -> Placed

Fit the animation into a width x height box and place it there, writing the result through SSPlayer::set_transform.

The box the host lays out is in pixels of the render target, so call this again when that box changes — on a resize, and after SSPlayer::set_animation if the packs differ in canvas. It is pure arithmetic over Placement::frame or SSPlayer::canvas_rect; nothing is measured and no GPU state is touched.

The returned Placed is what was written, so a host can read back the scale it got rather than recomputing it — and can tell the fit from the no-fit answer, which a collapsed box or an animation that is not set up both produce (see solve).

Source

pub fn canvas_size(&self) -> Option<(f32, f32)>

Canvas size of the currently playing animation.

Source

pub fn instance_child_frames(&self) -> Vec<(usize, f32)>

What frame each instance child of the root is on, keyed by part index.

A diagnostic, like SSPlayer::instance_node_count — and the only way to see that a child’s clock is running while its part is hidden, since a hidden child draws nothing to look at.

Source

pub fn instance_node_count(&self) -> usize

Total number of instance child nodes in the current tree. A non-zero count confirms external references were resolved and the tree was built.

Trait Implementations§

Source§

impl Default for SSPlayer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,