3 - Game Sprite
On its own, our Bird
Sprite doesn't do anything - we need to import it in another Sprite. Open src/index
and replace the starter code with what's shown on the right.
Firstly you'll see we've made a new Game
Sprite. This is our top-level Sprite which contains our entire game.
Again, it has a render
function returning an array of Sprites. In this case, we return our Bird
Sprite we just made. We need to pass a locally unique id
prop
to any custom Sprites we've made - here we pass an id
of "bird"
by calling the Bird
Sprite like Bird(props)
.
- JavaScript
- TypeScript
1import { makeSprite } from "@replay/core";
2import { Bird } from "./bird";
3
4export const Game = makeSprite({
5 render() {
6 return [
7 Bird({
8 id: "bird",
9 }),
10 ];
11 },
12});
13
1import { makeSprite, GameProps } from "@replay/core";
2import { Bird } from "./bird";
3
4export const Game = makeSprite<GameProps>({
5 render() {
6 return [
7 Bird({
8 id: "bird",
9 }),
10 ];
11 },
12});
13
Preview