Skip to content

Instantly share code, notes, and snippets.

@gbuszmicz
Created April 16, 2019 01:30
Show Gist options
  • Save gbuszmicz/9b4471064244ec4136605284a9606232 to your computer and use it in GitHub Desktop.
Save gbuszmicz/9b4471064244ec4136605284a9606232 to your computer and use it in GitHub Desktop.
Pixi slider component for React
import { CustomPIXIComponent } from 'react-pixi-fiber'
import * as PIXI from 'pixi.js'
const TYPE = 'Background'
export const behavior = {
customDisplayObject: props => new PIXI.Graphics(),
customApplyProps: function(instance, oldProps, newProps) {
const { fill, x, y, width, height, onClick } = newProps
const onPointerDown = event => {
onClick(event.data.getLocalPosition(instance.parent))
}
instance.clear()
instance.beginFill(fill)
instance.drawRect(x, y, width, height)
instance.endFill()
instance.interactive = true
instance.buttonMode = true
instance.on('pointerdown', onPointerDown)
},
}
export default CustomPIXIComponent(behavior, TYPE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment