Skip to content

Instantly share code, notes, and snippets.

@AdrienLemaire
Created November 12, 2020 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrienLemaire/cffb1f47639443582fa78ba9b104bc9e to your computer and use it in GitHub Desktop.
Save AdrienLemaire/cffb1f47639443582fa78ba9b104bc9e to your computer and use it in GitHub Desktop.
CodePen Home React PIXI - Sprite - Rotating Bunny - hooks style
// https://codepen.io/inlet/pen/aYLvrZ rewritten with hooks
import React, { useState } from "react";
import { Container, Sprite, Stage, useTick } from "@inlet/react-pixi";
const img = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/693612/IaUrttj.png";
const RotatingBunny: React.FC = () => {
const [rotation, setRotation] = useState(0);
useTick((delta) => delta && setRotation(rotation + 0.1 * delta));
return <Sprite image={img} scale={4} rotation={rotation} anchor={0.5} />;
};
const stageOptions = { backgroundColor: 0x012b30 };
const App: React.FC = () => (
<div>
<h1>Demo</h1>
<Stage width={500} height={500} options={stageOptions}>
<Container x={250} y={250}>
<RotatingBunny />
</Container>
</Stage>
</div>
);
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment