Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphics #66

Open
Hopchenko opened this issue Dec 8, 2016 · 7 comments
Open

Graphics #66

Hopchenko opened this issue Dec 8, 2016 · 7 comments
Assignees

Comments

@Hopchenko
Copy link

Could you please explain how to work with Graphics component. It will be better if you add the simple example.

@Izzimach
Copy link
Owner

Izzimach commented Dec 8, 2016

I have never used Graphics, so I can't really explain it. You might get some information by looking at this PR here.

@Izzimach Izzimach self-assigned this Dec 8, 2016
@Hopchenko
Copy link
Author

Hopchenko commented Dec 8, 2016 via email

@funkjunky
Copy link

I didn't notice this post when i posted my issue.

I just made a rect and circle component out of Graphics.

It could use more features, but it should show how it's possible to do shapes with react-pixi:

export class Rect extends React.Component {
    drawRect = ({ x, y, width, height, rotation }) => {
        this.refs.graphics.clear();
        this.refs.graphics.lineStyle(2, 0x0000FF, 1);
        this.refs.graphics.beginFill(0x0000FF, 1);
        this.refs.graphics.drawRect(0, 0, width, height);
        this.refs.graphics.endFill();
    }

    componentDidMount() {
        this.drawRect(this.props);
    }

    componentWillReceiveProps(props) {
        this.drawRect(props);
    }

    render() {
        return <Graphics ref='graphics' x={this.props.x} y={this.props.y}/>;
    }
}

@EloB
Copy link

EloB commented May 29, 2017

@funkjunky I think it's better to write like this. :)

export class Rect extends React.Component {
    drawRect = ({ x, y, width, height, rotation }) => {
        this.refs.graphics.clear();
        this.refs.graphics.lineStyle(2, 0x0000FF, 1);
        this.refs.graphics.beginFill(0x0000FF, 1);
        this.refs.graphics.drawRect(0, 0, width, height);
        this.refs.graphics.endFill();
    }

    componentDidMount() {
        this.drawRect(this.props);
    }

    shouldComponentUpdate(nextProps) {
        return !shallowEqual(this.props, nextProps);
    }

    componentWillUpdate() {
        this.drawRect(this.props);
    }

    render() {
        return <Graphics ref='graphics' x={this.props.x} y={this.props.y}/>;
    }
}

@matt-erhart
Copy link

Does anyone have a repo around somewhere with a graphics example? I can't seem to get this kind of thing to work.

@Hopchenko
Copy link
Author

Hopchenko commented Sep 6, 2017 via email

@Izzimach
Copy link
Owner

I try to support react-pixi when I can, but it's not much.
If you want to add examples for fix something do it and submit PR, it's OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants