Skip to main content

SsPlayerWeb

Struct SsPlayerWeb 

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

One character. Holds the playback tree and its placement in the scene — and no GPU resource at all, which is what makes it cheap to have many.

Implementations§

Source§

impl SsPlayerWeb

Source

pub async fn load_ssab( &self, bytes: Vec<u8>, pack: Option<String>, base_url: Option<String>, read: Option<Function>, ) -> Result<(), JsValue>

Register + select a .ssab, and load the textures it needs.

It loads the pack’s textures before returning and leaves setAnimation a pure selection. Texture loading belongs to initialisation, not to animation selection: switching motions is a frequent, synchronous operation that must not carry a Promise, so SsPlayerWeb::set_animation stays synchronous.

This is async because fetch and createImageBitmap are. That is the one place the asynchrony appears.

  • pack names the pack for external instance references (ref_anime_pack). Pass null/undefined — the usual case — to use the name the exporter wrote into the .ssab, which is the name those references are resolved against. A name of your own overrides it, and then any external instance reference to this pack stops resolving.
  • baseUrl is where the .ssab came from; reference-mode atlas paths are relative to it. Defaults to the document’s URL. Embedded packs ignore it.
  • read answers in place of fetch, as it does for SsPlayerWeb::load.

An atlas the renderer already has is left alone (“registered wins”), so N players of one pack load it once between them. An atlas that cannot be fetched or decoded is reported on the console and skipped, as in _load_external_ssabs’ ERR_PRINT and PackResolver’s console.warn: one missing image should not cost you the character.

Source

pub async fn load( &self, src: &str, read: Option<Function>, ) -> Result<(), JsValue>

Fetch a .ssab and everything it needs, then select it.

The shortest form: a URL is the one input that answers both questions a pack raises — what the bytes are, and what its sibling files resolve against. src may be absolute or relative (resolved against the document, like any URL a page uses), and the pack keeps the name the exporter gave it.

This is SSPlayer::load_with with the browser’s loader plugged in — the same walk a native host’s SSPlayer::load makes. Use SsPlayerWeb::load_ssab when the bytes have no URL at all — a bundler’s import — and pass baseUrl if that pack still has siblings to find.

read stands in for fetch when the files are not on a server: a dropped folder, an archive the page unpacked. It is handed each file’s absolute URL — src resolved against the document, everything after it resolved against src — and answers an ArrayBuffer, a Uint8Array or a Blob, or null for a file it does not have. So a page that files a dropped folder under URLs of its own choosing gets the whole walk:

const base = new URL('dropped/1/', location.href);
const files = new Map(dropped.map((f) => [new URL(f.path, base).href, f.file]));
await player.load(new URL('Ringo/Ringo.ssab', base).href, (url) => files.get(url));

The atlases are keyed by those URLs, as fetched ones are, so a second folder needs a base of its own: under the same one, an atlas that shares a name with the first folder’s is taken as already loaded.

One load at a time per player. Starting a second before the first has settled is rejected, because the two would otherwise race for the slot the player was lifted out of and one of them would be lost — await the promise, or chain the calls. Two different players load concurrently as usual, and share whatever atlases they have in common.

Source

pub async fn add_ssab( &self, bytes: Vec<u8>, pack: Option<String>, base_url: Option<String>, read: Option<Function>, ) -> Result<(), JsValue>

SsPlayerWeb::load_ssab without changing what plays: registers an additional pack for external instance references, and loads its assets too — a sub-animation’s cells come out of its own pack’s atlases.

Rarely needed, since SsPlayerWeb::load resolves those references itself; it is for packs that are not URL-addressable.

Source

pub fn animation_names(&self) -> Result<Vec<String>, JsValue>

The animation names in the loaded pack.

Source

pub fn current_animation(&self) -> Result<Option<String>, JsValue>

The animation currently set up, or undefined before the first setAnimation and again after a load replaced the pack.

Source

pub fn texture_refs(&self, pack: Option<String>) -> Result<Array, JsValue>

The atlases a registered pack asks for, as { key, path, embedded }[] in pack order. pack undefined selects the main pack.

The counterpart of SsContextWeb::add_texture: only the .ssab knows where its atlases were exported to, so a page showing a reference-mode pack fetches new URL(path, ssabUrl) for every entry whose embedded is false and registers the pixels by key. Embedded entries need no fetch — they arrive with the pack.

key is what the renderer is keyed by, not the slot the pack names the atlas by. The two differ whenever two packs could name one atlas alike, which a tool naming every project’s atlas spritemap1.png does — registering by the slot is how a page ends up drawing another project’s atlas, which is why the slot is not handed out here.

Source

pub fn embedded_textures(&self, pack: Option<String>) -> Result<Array, JsValue>

The atlases a registered pack carries, as { key, bytes }[] — the encoded images, not pixels. Empty for a reference-mode pack. pack undefined selects the main pack.

The embedded half of texture supply, and the counterpart of SsPlayerWeb::texture_refs: there is nothing to fetch, but there is still something to decode, and on this face the decoder is the browser. Hand each entry to SsContextWeb::add_texture_from_bytes.

It is what lets this face support embedded packs without carrying an image decoder into the bundle.

Source

pub fn missing_assets(&self) -> Result<Array, JsValue>

What the last load could not get, as { kind, name, slot }[]. Empty means everything the packs asked for arrived.

load rejects only when the .ssab itself is unreadable — one missing atlas must not cost you the character — so this is how a page tells a complete load from one that played anyway. kind is "texture" (its parts draw as white silhouettes) or "pack" (its parts do not appear).

Source

pub fn replaceable_cellmap_names( &self, pack: Option<String>, ) -> Result<Vec<String>, JsValue>

Every replaceable name in a pack — cellmap names and TextureChange targets both, the namespace SsPlayerWeb::set_cellmap_texture takes. pack null selects the main pack.

Source

pub fn set_cellmap_texture( &self, pack: Option<String>, name: &str, bitmap: &ImageBitmap, ) -> Result<(), JsValue>

Replace the texture a cellmap binds, from a premultiplied ImageBitmap the page decoded (createImageBitmap(blob, { premultiplyAlpha: 'premultiply' })).

pack null selects the main pack. name is one of SsPlayerWeb::replaceable_cellmap_names. The replacement should match the original atlas’s size and cell layout — the runtime’s UVs stay in the original cellmap’s pixel space. Rejects when the player is unbound, for a pack or name it cannot replace, and for a bitmap the device cannot hold — past its max_texture_dimension_2d, or closed — leaving the cellmap as it was.

Source

pub async fn set_cellmap_texture_from_bytes( &self, pack: Option<String>, name: String, bytes: Vec<u8>, ) -> Result<(), JsValue>

SsPlayerWeb::set_cellmap_texture from encoded image bytes (PNG); the library runs them through createImageBitmap. Decoded before anything changes, so a bad image leaves the cellmap as it was.

Source

pub fn restore_cellmap_texture( &self, pack: Option<String>, name: &str, ) -> Result<(), JsValue>

Undo a runtime override: point the cellmap back at its original atlas and drop the replacement from the renderer. A no-op if it was not overridden; rejects a pack or name the player cannot replace.

Source

pub fn is_cellmap_overridden( &self, pack: Option<String>, name: &str, ) -> Result<bool, JsValue>

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

Source

pub fn set_animation(&self, name: &str) -> Result<(), JsValue>

Select an animation: builds the instance tree, and the only call here that allocates. Starting playback is SsPlayerWeb::play, a separate call.

Source

pub fn play(&self) -> Result<(), JsValue>

Start from the head of the section, re-arming the loop count. Not a resume: it rewinds. Use SsPlayerWeb::resume to lift a hold.

Source

pub fn play_from(&self, start_frame: f32) -> Result<(), JsValue>

play() from startFrame rather than the head of the section.

Source

pub fn pause(&self) -> Result<(), JsValue>

Hold the current frame. Idempotent, and ignored while nothing is playing.

Source

pub fn resume(&self) -> Result<(), JsValue>

Lift a SsPlayerWeb::pause, carrying on from the same frame. Idempotent, and a no-op on a stopped animation.

Source

pub fn stop(&self) -> Result<(), JsValue>

Stop playback. The playhead stays where it stands; nothing rewinds.

Source

pub fn set_speed_scale(&self, speed: f32) -> Result<(), JsValue>

Playback rate multiplier (1.0 = as authored).

Source

pub fn speed_scale(&self) -> Result<f32, JsValue>

The speed in effect: 0 for a speed that was set to zero or below, since that is the stop it became.

Source

pub fn is_playing(&self) -> Result<bool, JsValue>

Whether this player is currently advancing.

Source

pub fn is_pausing(&self) -> Result<bool, JsValue>

Held in place rather than stopped: isPlaying stays true.

Source

pub fn is_playing_forward(&self) -> Result<bool, JsValue>

Which way the playhead is actually travelling — not the heading setPlaybackDirection configured, which playbackDirection reports. Under ping-pong the return leg runs backward while that still reads forward. Gate audio on this: SpriteStudio has no reverse audio.

Source

pub fn is_finished(&self) -> Result<bool, JsValue>

Every configured loop has played. Sticky, and never true under an infinite loop.

Source

pub fn seek(&self, frame: f32) -> Result<(), JsValue>

Jump to frame. Fractional values are honoured.

Source

pub fn frame_no(&self) -> Result<f32, JsValue>

Current playhead position, fractional.

Source

pub fn start_frame(&self) -> Result<i32, JsValue>

First frame of the range being played. Follows setAnimationSection.

Source

pub fn end_frame(&self) -> Result<i32, JsValue>

Last frame of the range being played.

Source

pub fn total_frames(&self) -> Result<i32, JsValue>

Length of that range, both ends inclusive — feed it to a scrubber.

Source

pub fn set_loop_count(&self, count: i32) -> Result<(), JsValue>

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

Source

pub fn loop_count(&self) -> Result<i32, JsValue>

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

Source

pub fn remaining_loops(&self) -> Result<i32, JsValue>

How many cycles of the loop count are left; 0 with no animation.

Source

pub fn set_frame_rate(&self, fps: i32) -> Result<(), JsValue>

Override the advance rate in fps. Prefer setSpeedScale, which scales playback without replacing the authored rate.

Source

pub fn frame_rate(&self) -> Result<i32, JsValue>

The rate the animation advances at.

Source

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

Restrict playback to start..=end of the current animation. Call it after setAnimation, which rebuilds the tree and takes the section with it. Throws, changing nothing, on an end before the start when both are inside the animation; an end outside it is the animation’s edge.

Source

pub fn set_playback_direction( &self, direction: i32, style: i32, ) -> Result<(), JsValue>

direction: 0 forward, 1 backward. style: 0 normal, 1 ping-pong. Set as a pair — pass the current value for whichever you are not changing.

Source

pub fn playback_direction(&self) -> Result<i32, JsValue>

0 forward, 1 backward.

Source

pub fn playback_style(&self) -> Result<i32, JsValue>

0 normal, 1 ping-pong.

Source

pub fn set_sub_frame_enabled(&self, enabled: bool) -> Result<(), JsValue>

On (the default) draws between authored frames; off floors the frame that is drawn, pinning playback to whole ones.

The playhead keeps its fraction either way (frameNo reports it unrounded), and so does the stepping of instance and effect children. This affects only what is drawn.

Source

pub fn sub_frame_enabled(&self) -> Result<bool, JsValue>

See setSubFrameEnabled.

Source

pub fn set_frame_skip_enabled(&self, skip: bool) -> Result<(), JsValue>

On (the default) keeps playback on the wall clock by dropping frames; off advances exactly one frame per frame() call.

Source

pub fn frame_skip_enabled(&self) -> Result<bool, JsValue>

See setFrameSkipEnabled.

Source

pub fn find_part_index(&self, name: &str) -> Result<i32, JsValue>

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

Source

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

Force-hide a part (hide = true) 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 sub-tree.

Source

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

Revert a part to the animation’s own visibility.

Source

pub fn set_part_color_override_by_index( &self, part: u32, rgba: u32, blend_op: u8, priority: u8, ) -> Result<(), JsValue>

Override a part’s colour. blendOp: 0 mix, 1 mul, 2 add, 3 sub. rgba is packed 0xRRGGBBAA in the authored 8-bit sRGB space — do not pre-multiply it. priority: 0 until the next keyframe, 1 until the next animation, 2 permanent. Normal parts only.

Source

pub fn set_part_color_override_corners_by_index( &self, part: u32, corners: &[u8], blend_op: u8, priority: u8, ) -> Result<(), JsValue>

Four-corner colour override, for a gradient. corners is 16 bytes in the runtime’s order — left-top, right-top, left-bottom, right-bottom, each [r, g, b, a]. Otherwise as setPartColorOverride.

Source

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

Revert a part to the animation’s own colour.

Source

pub fn set_part_cell_override_by_index( &self, part: u32, cellmap_name: &str, cell_name: &str, priority: u8, ) -> Result<(), JsValue>

Make a part draw a different cell. cellmapName is written without the .ssce extension. Normal and Mask parts only; throws when the cell cannot be resolved against the loaded pack.

Source

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

Revert a part to the animation’s own cell.

Source

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

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

Source

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

Revert a part to the animation’s own visibility, by name.

Source

pub fn set_part_color_override( &self, part: &str, rgba: u32, blend_op: u8, priority: u8, ) -> Result<(), JsValue>

Override a part’s colour by name. Arguments as setPartColorOverrideByIndex.

Source

pub fn set_part_color_override_corners( &self, part: &str, corners: &[u8], blend_op: u8, priority: u8, ) -> Result<(), JsValue>

Four-corner colour override by name. Arguments as the ByIndex sibling.

Source

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

Revert a part to the animation’s own colour, by name.

Source

pub fn set_part_cell_override( &self, part: &str, cellmap_name: &str, cell_name: &str, priority: u8, ) -> Result<(), JsValue>

Make a part draw a different cell, by name.

Source

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

Revert a part to the animation’s own cell, by name.

Source

pub fn part_transform(&self, part: &str) -> Result<Vec<f32>, JsValue>

A part’s current-frame transform by name, as the six affine terms, or an empty array when the name is unknown.

Source

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

Whether the part is hidden on the frame the last frame() built, or undefined when the pack has no such part. An override shows from the next frame().

The companion to partTransform, which reports where a part would be whether or not it is drawn — a host following a part needs both.

Source

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

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

A skinned mesh cannot be followed with partTransform: its node stays at the setup position (near the character root) while the bones move the visible vertices, so a follower would snap to the root. A picker can use this to warn, or to steer the choice to a null / bone part. A rigid (deform-only) mesh follows correctly and reports false.

Source

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

Index form of isPartHidden, for the partIndex an event carries or a slot in partNames; undefined when part is out of range.

Source

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

Index form of isPartSkinnedMesh; undefined when part is out of range.

Source

pub fn part_names(&self) -> Result<Vec<String>, JsValue>

Every part name, in part-index order — what turns the partIndex an event carries back into something a human reads, and what fills a part picker.

An unnamed part holds its slot as an empty string, so the array stays index-aligned. length is the part count, and unlike partCount, which is 0 until an animation is set up, it is there as soon as a pack is bound.

Source

pub fn cellmap_names(&self) -> Result<Vec<String>, JsValue>

Every cellmap name in the pack, without the .ssce extension — the namespace setPartCellOverride takes.

Source

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

The cell names inside one cellmap — the other half of what setPartCellOverride takes.

Source

pub fn clear_all_part_overrides(&self) -> Result<(), JsValue>

Drop every override on the root animation at once.

Source

pub fn part_count(&self) -> Result<usize, JsValue>

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

Source

pub fn set_track_animation(&self, track: u32, name: &str) -> Result<(), JsValue>

Put name on track, replacing what it was playing. Track 0 is better set with setAnimation, which rebuilds the instance tree. On track 0 it still makes name the current animation.

Source

pub fn track_count(&self) -> Result<u32, JsValue>

Number of tracks, empty ones included; 0 before an animation is set up.

Source

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

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

Source

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

How much of track survives onto the pose below. Not clamped: above 1 extrapolates, 0 or below contributes nothing.

Source

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

track’s alpha, or undefined when there is no such track.

Source

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

blend: 0 = mix (lerp onto what is below), 1 = additive (offset from the setup pose).

Source

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

0 = mix, 1 = additive.

Source

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

sync: 0 = free (an animation laid on the track starts from its head), 1 = start (it starts at the phase track 0 stands at). Set it before laying; setAnimation resets every track to free.

Source

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

0 = free, 1 = start.

Source

pub fn crossfade( &self, track: u32, name: &str, duration_ms: f32, ) -> Result<(), JsValue>

Fade track to name over durationMs, starting from whatever it is playing. Advanced by frame(). On track 0, name takes over from the call on: it is the current animation, its state is what isFinished reports, and it plays with the speed, direction and loop count the page set. The instance tree is not rebuilt; the instance and effect parts belong to the pack, so the running children carry on.

Source

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

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

Source

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

How far the fade on track has got, 0 to 1; undefined when it is not fading.

Source

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

Stop the fade on track, leaving alpha and weights where they stand.

Source

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

Seek track’s animation — how a continuous-control axis is driven.

Source

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

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

Source

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

track’s own playback speed; 0 parks it, which is how a scrubbed axis stays where setTrackFrame puts it.

Source

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

track’s speed (see setTrackSpeed), or undefined when there is no such track.

Source

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

setFrameRate for one track.

Source

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

The rate track’s animation plays at, the override or the authored rate; 0 for a track with neither.

Source

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

setFrameSkipEnabled for one track.

Source

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

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

Source

pub fn set_track_playback_direction( &self, track: u32, direction: i32, style: i32, ) -> Result<(), JsValue>

setPlaybackDirection for one track, with the same 0 / 1 values.

Source

pub fn track_playback_direction( &self, track: u32, ) -> Result<Option<i32>, JsValue>

0 = forward, 1 = backward.

Source

pub fn track_playback_style(&self, track: u32) -> Result<Option<i32>, JsValue>

0 = normal, 1 = ping-pong.

Source

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

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

Source

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

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

Source

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

Whether track’s animation has played its loop count out and holds its last frame. A state, as isFinished is for track 0; there is no edge.

Source

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

Whether the last frame() wrapped track’s animation back to its start, as justLooped is for track 0.

Source

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

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, Infinity, silences it from the moment the fade begins; 0.5 keeps it firing for the first half. Kept by the track. 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, ) -> Result<Option<f32>, JsValue>

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

Source

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

The source carrying track’s animation; undefined when it has none.

Source

pub fn add_track_source( &self, track: u32, name: &str, weight: f32, ) -> Result<u32, JsValue>

Lay name on track beside what it already carries, at weight, and return its handle. On an empty track it becomes the main source.

Source

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

A source’s share within its track; weights are ratios.

Source

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

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

Source

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

Seek one source — how a page keeps sources of different lengths in step.

Source

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

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

Source

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

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

Source

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

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

Source

pub fn just_started(&self) -> Result<bool, JsValue>

Whether the last frame() was the first to run after a play() / playFrom() — true for exactly one call. Not raised by resume(), which carries on rather than starting.

Source

pub fn just_looped(&self) -> Result<bool, JsValue>

Whether the last frame() crossed a loop boundary. One report per call however many cycles it crossed.

Source

pub fn just_finished(&self) -> Result<bool, JsValue>

Whether the last frame() completed playback — true for exactly one call, unlike the sticky isFinished. Never true under an infinite loop, and not raised by stop().

Source

pub fn events(&self) -> Result<Array, JsValue>

Timeline events the last frame() crossed, as an array of plain objects tagged by kind:

{ kind: 'userData', partIndex, integer?, rect?, point?, text? }
{ kind: 'signal', partIndex, commandId, params: [{ id, value }] }
{ kind: 'audio', partIndex, soundName, soundListNameHash, soundNameHash, loopNum }

Every kind also carries frameNo (the frame the key is authored on), partName, and source: the handle of the source on the track stack that fired it, which tells events apart once another source has opted in with setSourceEventThreshold.

Frames skipped over are still represented: a long tick reports every frame it stepped through, not just the one it landed on. Empty on a tick that crossed nothing, and on a culled player, which does not advance; a hidden one reports as usual.

Source

pub fn part_transform_by_index(&self, part: u32) -> Result<Vec<f32>, JsValue>

The part’s transform on the current frame as the 2D affine [m00, m01, m10, m11, tx, ty] — the same six numbers ssplayer-webgl’s getPartTransform returns, in animation-local (Y-down) space, with neither setTransform nor the canvas projection applied.

Empty when no animation is set up or part is out of range. Read it after frame(): it describes the frame that produced. Hidden parts still report where they would have been.

Source

pub fn set_transform( &self, x: f32, y: f32, scale_x: f32, scale_y: f32, rotation: f32, ) -> Result<(), JsValue>

Place this player in the scene, in pixels from the canvas centre, with y measured downward (as partTransform reports, and as ForWeb’s offsetY means it). rotation is in radians.

Source

pub fn reset_transform(&self) -> Result<(), JsValue>

Back to the identity placement (centred, unscaled, unrotated).

Source

pub fn canvas_rect(&self) -> Result<JsValue, JsValue>

The authored canvas of the animation now playing, as { x, y, width, height } in player-local units — the box SsPlayerWeb::fit_into fits when you pass no frame of your own.

undefined when no animation is set up. It is the frame the artist composed in, placed against the origin by the animation’s pivot, not a measured bounding box.

Source

pub fn fit_into( &self, width: f32, height: f32, options: Option<Object>, ) -> Result<Object, JsValue>

Fit the animation into a width x height box and place it there, as setTransform would. Returns what was written, as { x, y, scaleX, scaleY }.

player.fitInto(canvas.width, canvas.height, { fit: 'contain', align: 'bottom' });

Every field of the options object is optional:

  • fit — 'contain' (default) | 'cover' | 'none'
  • align — 'center' (default), 'top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'
  • frame — { x, y, width, height } in player-local units. Supply it and nothing is read from the pack
  • offsetX / offsetY — pixels, applied after the fit
  • scale — a multiplier on top of the fit’s scale (default 1)
  • flipX / flipY — mirrors; the alignment follows them
  • rotation — radians, passed straight through

The size is in canvas pixels, so call it again on resize and after setAnimation when the canvas differs. A collapsed box, or no animation, places the player centred and unscaled rather than throwing. An unrecognised fit or align does throw, naming what it accepts.

Source

pub fn set_order(&self, order: i32) -> Result<(), JsValue>

Draw order within the canvas; lower draws first.

Source

pub fn order(&self) -> Result<i32, JsValue>

The draw order setOrder set.

Source

pub fn set_visible(&self, visible: bool) -> Result<(), JsValue>

Hide this player. A hidden player draws nothing but keeps playing: its playhead advances and its events are reported.

Source

pub fn is_visible(&self) -> Result<bool, JsValue>

Whether this player draws, as setVisible set it.

Source

pub fn set_culled(&self, culled: bool) -> Result<(), JsValue>

Cull this player. A culled player is skipped by both update and draw, so it costs nothing and its playhead stops where it was.

Source

pub fn is_culled(&self) -> Result<bool, JsValue>

Whether this player is culled, as setCulled set it.

Source

pub fn set_alpha(&self, alpha: f32) -> Result<(), JsValue>

Player-level fade in 0..1, multiplied into every part — so overlapping parts read more opaque than alpha, unless the canvas fades each player as one layer (SsSurfaceWeb.setGroupAlpha).

Source

pub fn alpha(&self) -> Result<f32, JsValue>

The player-level fade in effect, after setAlpha clamped it to 0..1.

Source

pub fn set_tint(&self, rgb: u32) -> Result<(), JsValue>

Player-level tint as 0xRRGGBB, multiplied into every part after the PartColor blend. 0xffffff (the default) leaves colours untouched — the same property tint names on @spritestudio/ssplayer-webgl.

Source

pub fn tint(&self) -> Result<u32, JsValue>

The player-level tint as 0xRRGGBB.

Source

pub fn set_crowd( &self, placements: &[f32], tints: Option<Vec<u32>>, ) -> Result<(), JsValue>

Draw this one playhead once at each member’s placement: a crowd that costs one player’s evaluation and draw calls, however large.

placements holds six numbers a member — x, y, scaleX, scaleY, rotation, alpha, the first five in setTransform terms and composed under it, the alpha multiplied into the player’s — and tints, when given, one 0xRRGGBB a member. An empty array draws the player once again. Throws, leaving the crowd as it was, when placements is not a whole number of members, tints does not match it, or there are more than 4096.

Everything else is shared: the frame, the events (reported once), the masks and the effects. Each draw is issued for every member in turn, so where two members overlap their parts interleave, and masks clip correctly only where members do not overlap.

Source

pub fn crowd_count(&self) -> Result<usize, JsValue>

How many members setCrowd last gave this player; 0 when it draws once.

Source

pub fn canvas_size(&self) -> Result<Vec<f32>, JsValue>

The authored canvas size of the selected animation, as [width, height], or an empty array when nothing is loaded. Useful for scaling a character to fit the element it was dropped into.

Source

pub fn destroy(&self)

Remove this player from its canvas. Safe to call twice; afterwards every method on this handle reports that it is destroyed rather than acting on whichever player later reuses the slot.

Trait Implementations§

Source§

impl From<SsPlayerWeb> for JsValue

Source§

fn from(value: SsPlayerWeb) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for SsPlayerWeb

Source§

type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: Self::Abi) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for SsPlayerWeb

Source§

type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> Self::Abi

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for SsPlayerWeb

Source§

type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<SsPlayerWeb>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl NullableFromWasmAbi for SsPlayerWeb

Source§

fn is_null(abi: &Self::MaybeAbi) -> bool

Tests the ABI value for Nullable::Null.
Source§

impl NullableIntoWasmAbi for SsPlayerWeb

Source§

fn null() -> Self::MaybeAbi

Returns the ABI value for Nullable::Null, which JS reads as null. Read more
Source§

impl OptionFromWasmAbi for SsPlayerWeb

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for SsPlayerWeb

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for SsPlayerWeb

Source§

type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<SsPlayerWeb>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for SsPlayerWeb

Source§

type Abi = WasmPtr<WasmRefCell<SsPlayerWeb>>

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<SsPlayerWeb>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl SupportsConstructor for SsPlayerWeb

Source§

impl SupportsInstanceProperty for SsPlayerWeb

Source§

impl SupportsStaticProperty for SsPlayerWeb

Source§

impl TryFromJsValue for SsPlayerWeb

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

const NULLABLE: bool = false

Whether Self accepts null as a distinct value space, as Nullable<T> does. An enclosing Option then passes null through instead of reading it as None, so Option<T> is itself nullable exactly when T is not. JsValue does not set this: it accepts null as one value among all of them, not as a distinct space, and Option<JsValue> reads it as None like the ABI does. This is the JS-value side of NullableFromWasmAbi, which claims null at the ABI.
Source§

impl VectorFromWasmAbi for SsPlayerWeb

Source§

type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi

Source§

unsafe fn vector_from_abi(js: Self::Abi) -> Box<[SsPlayerWeb]>

Source§

impl VectorIntoWasmAbi for SsPlayerWeb

Source§

impl WasmDescribe for SsPlayerWeb

Source§

impl WasmDescribeVector for SsPlayerWeb

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.

Source§

impl<T> MaybeFromWasmAbi for T

Source§

type MaybeAbi = <T as FromWasmAbi>::Abi

The ABI of Option<Self>.
Source§

unsafe fn from_maybe_abi(js: <T as FromWasmAbi>::Abi) -> T

Recovers a value from the Option<Self> ABI, once is_none has ruled None out. Read more
Source§

unsafe fn try_from_maybe_abi( js: <T as FromWasmAbi>::Abi, ) -> Result<T, &'static str>

Source§

fn is_none(js: &<T as FromWasmAbi>::Abi) -> bool

Tests the ABI value for None.
Source§

impl<T> MaybeIntoWasmAbi for T

Source§

type MaybeAbi = <T as IntoWasmAbi>::Abi

The ABI of Option<Self>.
Source§

fn into_maybe_abi(self) -> <T as IntoWasmAbi>::Abi

Converts a value into the Option<Self> ABI.
Source§

fn none() -> <T as IntoWasmAbi>::Abi

Returns the ABI value for None, which JS reads as undefined. Read more
§

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

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
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