Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update animated sprite example #530

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion packages/docs/docs/components/AnimatedSprite.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,40 @@ https://pixijs.download/v7.x/docs/PIXI.AnimatedSprite.html
```jsx live noInline
// import { render } from 'react-dom';
// import { Stage, Container, AnimatedSprite } from '@pixi/react';
// import { Assets, Texture } from 'pixi.js';

async function makeAnimatedSpriteTextures() {
await Assets.load('https://pixijs.com/assets/spritesheet/mc.json');
// create an array to store the textures
const explosionTextures = [];
let i;

for (i = 0; i < 26; i++) {
const texture = Texture.from(`Explosion_Sequence_A ${i + 1}.png`);

explosionTextures.push(texture);
}

return explosionTextures;
}

const textures = makeAnimatedSpriteTextures();

render(
export const AnimatedExplosion() {
const [textures, setTextures] = React.useState<Texture[]>([]);

React.useEffect(() => {
(async () => {
const newTextures = await makeAnimatedSpriteTextures();
setTextures(newTextures);
})();
}, []);

if (textures.length === 0) {
return null; // or a loading indicator
}

return(
<Stage width={300} height={300} options={{ backgroundColor: 0xeef1f5 }}>
<Container position={[150, 150]}>
<AnimatedSprite
Expand All @@ -34,6 +64,7 @@ render(
</Container>
</Stage>,
);
}
```

## Example
Expand Down
Loading