README
ReactPixiFiber – React Fiber renderer for PixiJS
ReactPixiFiber is a JavaScript library for writing PixiJS applications using React declarative style in React 16.
For React <16.0.0 see react-pixi
.
Demo
See Rotating Bunny demo.
Usage
With ReactDOM
import { render } from "react-dom";
import { Sprite, Stage } from "react-pixi-fiber";
import bunny from "./bunny.png";
function Bunny(props) {
return <Sprite texture={PIXI.Texture.from(bunny)} {...props} />;
}
render(
<Stage options={{ backgroundColor: 0x10bb99, height: 600, width: 800 }}>
<Bunny x={200} y={200} />
</Stage>,
document.getElementById("container")
);
This example will render PIXI.Sprite
object into a Root Container of PIXI.Application
on the page.
The HTML-like syntax; called JSX is not required to use with this renderer, but it makes code more readable. You can use Babel with a React preset to convert JSX into native JavaScript.
Without ReactDOM
import { render, Text } from "react-pixi-fiber";
import * as PIXI from "pixi.js";
// Setup PixiJS Application
const canvasElement = document.getElementById("container")
const app = new PIXI.Application({
backgroundColor: 0x10bb99,
view: canvasElement,
width: 800,
height: 600,
});
render(
<Text text="Hello World!" x={200} y={200} />,
app.stage
);
This example will render PIXI.Text
object into a Root Container of PIXI Application (created as app
) inside the <canvas id="container"></canvas>
element on the page.
Running Examples
- Run
yarn install
(ornpm install
) in the repository root. - Run
yarn install
(ornpm install
) in theexamples
directory. - Run
yarn start
(ornpm run start
) in theexamples
directory. - Wait few seconds and browse examples that will open in new browser window.
Installing
The current version assumes React >16.0.0 and PixiJS >4.4.0
yarn add react-pixi-fiber
or
npm install react-pixi-fiber --save
This package works flawlessly with Create React App – see examples above, they already use it.
react-pixi
Migrating from It is possible to use React Pixi Fiber as a drop-in replacement for react-pixi
.
There are two options:
import
/ require
statements
Changing Change:
import ReactPIXI from "react-pixi";
// or
const ReactPIXI = require("react-pixi");
to:
import ReactPIXI from "react-pixi-fiber/react-pixi-alias";
// or
const ReactPIXI = require("react-pixi-fiber/react-pixi-alias");
webpack
resolve alias
Using resolve: {
alias: {
'react-pixi