Skip to content

Instantly share code, notes, and snippets.

@vojto
Created March 5, 2020 14:06
Show Gist options
  • Save vojto/b85df973889d8ad572c3b85ec976539e to your computer and use it in GitHub Desktop.
Save vojto/b85df973889d8ad572c3b85ec976539e to your computer and use it in GitHub Desktop.
import { Graphics } from 'pixi.js';
import { PixiComponent, Stage } from '@inlet/react-pixi';
const Rectangle = PixiComponent('Rectangle', {
create: props => new Graphics(),
applyProps: (instance, oldProps, props) => {
const { x, y, width, height, fill, alpha } = props;
if (x !== oldProps.x || y !== oldProps.y || width !== oldProps.width || height !== oldProps.height || fill !== oldProps.fill) {
instance.clear();
instance.beginFill(fill);
instance.drawRect(x, y, width, height);
instance.endFill();
}
if (alpha !== oldProps.alpha) {
instance.alpha = alpha;
}
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment