Created
April 16, 2019 01:30
-
-
Save gbuszmicz/9b4471064244ec4136605284a9606232 to your computer and use it in GitHub Desktop.
Pixi slider component for React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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