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

Ability to draw on canvas only when needed (no rAF ticker) #68

Closed
slorber opened this issue Aug 14, 2018 · 3 comments
Closed

Ability to draw on canvas only when needed (no rAF ticker) #68

slorber opened this issue Aug 14, 2018 · 3 comments

Comments

@slorber
Copy link

slorber commented Aug 14, 2018

Hi,

Currently, if I have a stage that does not change over time, the Pixi.Application will create a ticker and re-render the stage on every frame. I think it does not make much sense and that we should only re-render when the react component re-render, so that using a PureComponent stage would help prevent re-rendering a stage that does not change.

More infos here:

This is what I see, when profiling and doing nothing at all in my browser:

image

I think in such case the browser should not do any work

@michalochman
Copy link
Owner

Hi @slorber, thanks for reporting however this is intended behaviour by default, you are only considering the most basic case. Please see discussion in #48 which also shows some examples.

@slorber
Copy link
Author

slorber commented Aug 14, 2018

Thanks @michalochman

I've found a workaround anyway

class OptimizedStage extends React.PureComponent {
  componentDidMount() {
    this.renderStage();
  }
  componentDidUpdate() {
    this.renderStage();
  }
  renderStage = () => this.application.render();
  render() {
    return (
      <Stage
        {...this.props}
        options={{
          ...this.props.options,
          autoStart: false,
        }}
        ref={ref => {
          if ( ref ) {
            this.application = ref._app;
          }
          else {
            this.application = null;
          }
        }}
      />
    )
  }
}

Didn't think of using the context to get access to the app, that would probably be more convenient that my current code based on refs

@michalochman
Copy link
Owner

FYI You also don't need to use provided <Stage> component, it is available out of convenience. If you don't need react-dom at all then it's better to render without it by instantiating Pixi Application and setting the options there.

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

2 participants