Skip to content

Components at a glance ​

Four components and five hooks, and a button in a package of its own. Most apps use one component and no hooks.

Use it when
<SpriteStudioView>You have one animation. The default.
<SpriteStudioScene> + <SpriteStudioSprite>You have many, and want one canvas and one clock for the lot.
<SpriteStudioPartAnchor>A view should ride on a part — a health bar over a head.
<SpriteStudioButton>The animation is a button. From react-native-spritestudio-ui.

<SpriteStudioView> ​

One animation, fitted to its own box. An ordinary React Native view with a Skia canvas and a frame loop inside it.

tsx
import { SpriteStudioView } from 'react-native-spritestudio'

<SpriteStudioView
  source="ss/Ringo/Ringo.ssab"
  animation="wait1"
  fit="contain"
  style={{ width: '100%' }}
/>
Prop group
What playssource, animation, transitionMs, playing, speed, loop
Where it landsfit, align, offset, scale, flipX, flipY, style
The boxframe, frameScope, measureFrames
ReactingonUserData, onAudio, onSignal, onLoad, onError, onAnimationFinished, onAnimationLooped, onAnimationStarted, onAnimationChanged
Overridingparts, textures
While loadingplaceholder
Over itchildren, laid over the animation's box
A <View>'s owntestID, the accessibility props, pointerEvents, onLayout

Given no size, it lays out like an <Image> of the authored canvas — see Basic playback.

ref.current.player is the SpriteStudioPlayer — seek, switch animation, read the content box.

Twenty of these is twenty canvases

Each one owns a canvas and a requestAnimationFrame loop. For a cast, use a scene.

<SpriteStudioScene> ​

Many animations, one canvas and one clock. Holds sprites; draws nothing itself beyond the canvas they share.

tsx
import { SpriteStudioScene, SpriteStudioSprite } from 'react-native-spritestudio'
import { SsAssets } from './ss-assets' // the typed manifest from Quick Start

<SpriteStudioScene style={{ flex: 1 }} paused={backgrounded}>
  <SpriteStudioSprite source={SsAssets['Ringo/Ringo']} x={100} y={200} />
  <SpriteStudioSprite source={SsAssets['Ringo/Ringo']} x={260} y={200} z={1} />
</SpriteStudioScene>
Prop
childrenThe sprites.
styleThe canvas's box.
pausedStops the clock for every sprite at once.
onErrorThe frame loop stopped. Without one, the error goes to console.error.

<SpriteStudioSprite> ​

One animation inside a scene — a position and a draw order, not a view. It renders nothing of its own; the scene's canvas draws it.

tsx
<SpriteStudioSprite
  source={SsAssets['Ringo/Ringo']}
  animation="walk"
  x={100}
  y={200}
  z={1}
/>

Everything about which animation and how it plays is shared with <SpriteStudioView>. What differs is placement: x, y, width, height, align, scale, flipX, flipY, z.

Outside a scene it warns and draws nothing. See Many animations: a scene.

<SpriteStudioPartAnchor> ​

Pins its children to a part. In a <SpriteStudioView>'s children it finds that view's player; anywhere else, pass one as player.

tsx
<SpriteStudioView source={SsAssets['Ringo/Ringo']}>
  <SpriteStudioPartAnchor partName="head">
    <HealthBar />
  </SpriteStudioPartAnchor>
</SpriteStudioView>
PropDefault
partNameThe part to follow.
playerthe enclosing view's
rotationtrueTurn with the part.
scalefalseScale with the part.

See Part overrides & following.

<SpriteStudioButton> ​

From react-native-spritestudio-ui, a package of its own. A <SpriteStudioView> that is a button: each state — normal, hover, pressed, disabled, focused — plays the section of one animation that starts at the label of its name.

tsx
import { SpriteStudioButton } from 'react-native-spritestudio-ui'

<SpriteStudioButton source="ss/ui/start.ssab" accessibilityLabel="Start" onPress={start} />
Prop
clipsA section of your own in place of a state's label.
hitParts, hitOnArtworkA press counts only on these parts' outlines, or on any part's.
reducedMotionHold each state still. Omitted, the system setting decides.
accessibilityLabelRead as a button. Without one it is decoration.

The view's props that load and place the animation apply, and so do a <Pressable>'s; playing, loop and transitionMs do not. See UI buttons.

Hooks ​

You can build everything above without these. Reach for them when the components do not fit.

useSsPartTransform ​

Follows a part with a Reanimated shared value — a health bar over a head. The one hook an ordinary app is likely to want.

tsx
// in a component rendered inside <SpriteStudioView>'s children
const player = useSsViewPlayer()
const transform = useSsPartTransform(player, 'head')

Returns SharedValue<SsPartScreenTransform> in view pixels, root transform applied. See Part overrides & following and Reanimated.

useSsViewPlayer ​

The player of the <SpriteStudioView> whose children the caller is in, or null outside one — what a follower of your own passes to useSsPartTransform.

useSsTextures ​

Decodes replacement atlases into SkImages. The hook behind the textures prop, exported for callers who want the decoded images themselves. Returns null until every texture has decoded.

tsx
const images = useSsTextures({ Ringo: require('./winter.png') })

See Textures & resources.

useSpriteStudioPlayer ​

Owns one SpriteStudioPlayer for a component: loads it, keeps the transport props on it, reports when it is drawable. Deliberately not a clock — who advances the player is the caller's business.

tsx
const { player, measured, ready } = useSpriteStudioPlayer(props)

This is the half <SpriteStudioView> and <SpriteStudioSprite> share. Use it if you are writing your own component and want the loading and prop-syncing without the canvas.

useSsScene ​

Returns the scene registry a sprite enrols in, or null outside a scene. Mostly here so a component can say plainly that it needs a scene rather than rendering an empty box.

Everything else ​

The exported surface beyond this — SpriteStudioPlayer, SsInternalPlayer, SsTextureRegistry, the caches, ssPreload, ssCheckForLeaks, the override vocabulary, SsRuntimeModule — is covered by Where to start and the generated reference.