Giter VIP home page Giter VIP logo

Comments (7)

matthieu-foucault avatar matthieu-foucault commented on August 22, 2024 7

FYI, using pixi-viewport is as simple as

import { CustomPIXIComponent } from 'react-pixi-fiber';
import Viewport from 'pixi-viewport';

const TYPE = 'Viewport';
const behavior = {
  customDisplayObject: props => {
    return new Viewport({
      screenWidth: props.app.renderer.width,
      screenHeight: props.app.renderer.height,
      worldWidth: 1000,
      worldHeight: 1000,
      interaction: props.app.renderer.plugins.interaction,
    }).drag()
      .pinch()
      .wheel()
      .decelerate();
  },
};

export default CustomPIXIComponent(behavior, TYPE);

and then use with:

      <Stage
        width={STAGE_WIDTH}
        height={STAGE_HEIGHT}
        options={STAGE_OPTIONS}
      >
        <AppContext.Consumer>
          {app =>
            <Viewport app={app}>
              {/* add display objects here */}
            </Viewport>
          }
        </AppContext.Consumer>
      </Stage>

I can make a PR to add it to the examples if you want

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024 1

Hey @fbove, yes you just need to create Custom Component. We have 2 examples available, one with PIXI.Graphics and one usage with children.

I originally planned to add pixi-viewport to examples but never really had time to do it.

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024

Hey @saricden, unfortunately that's the slowness of setState.

However, this should be easy to implement panning using davidfig/pixi-viewport and hooking into Custom Components API.

Additionally, you can take a look at #22 which was an attempt to introduce viewport before Custom Components API was added to react-pixi-fiber.

from react-pixi-fiber.

nervestaple avatar nervestaple commented on August 22, 2024

a pattern I've been using with some success is using the ticker to semi-synchronize / throttle state updates -- tracking the elapsed time in state and using sCU to only render every 16ms

from react-pixi-fiber.

fbove avatar fbove commented on August 22, 2024

Hi @michalochman, is there any example integrating pixi-viewport with react-pixi-fiber in component mode (With ReactDOM). I'm on need of dragging and zooming, and that library seems pretty nice.
Hoooking it using Custom Component API is the solution?

Any advice/example would be appreciated.

from react-pixi-fiber.

michalochman avatar michalochman commented on August 22, 2024

@matthieu-foucault that would be great!

from react-pixi-fiber.

saricden avatar saricden commented on August 22, 2024

@matthieu-foucault @michalochman awesome, cheers guys! 🍻

from react-pixi-fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.