Closed RJWadley closed 1 year ago
Thank you! I hope this gets merged.
I have tried this on a next.js
project, but I'll get Cannot read properties of undefined (reading 'shared')
.
I'm using it like this in a useEffect
hook:
useEffect(() => {
if (typeof window === 'undefined') return;
const app = new PIXI.Application({ width: 500, height: 400 });
containerRef.current.appendChild(app.view);
// create viewport
const viewport = new Viewport({
screenWidth: window.innerWidth,
screenHeight: window.innerHeight,
worldWidth: 1000,
worldHeight: 1000,
events: app.renderer.events, // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
});
// add the viewport to the stage
app.stage.addChild(viewport);
// activate plugins
viewport.drag().pinch().wheel().decelerate();
// add a red box
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE));
sprite.tint = 0xff0000;
sprite.width = sprite.height = 100;
sprite.position.set(100, 100);
}, []);
I have also tested with dynamic import:
useEffect(() => {
(async () => {
if (typeof window === 'undefined') return;
const pv = await import('pixi-viewport');
const app = new PIXI.Application({ width: 500, height: 400 });
containerRef.current.appendChild(app.view);
// create viewport
const viewport = new pv.Viewport({
screenWidth: window.innerWidth,
screenHeight: window.innerHeight,
worldWidth: 1000,
worldHeight: 1000,
events: app.renderer.events, // the interaction module is important for wheel to work properly when renderer.view is placed or scaled
});
// add the viewport to the stage
app.stage.addChild(viewport);
// activate plugins
viewport.drag().pinch().wheel().decelerate();
// add a red box
const sprite = viewport.addChild(new PIXI.Sprite(PIXI.Texture.WHITE));
sprite.tint = 0xff0000;
sprite.width = sprite.height = 100;
sprite.position.set(100, 100);
})();
}, []);
What am I missing something?
pixi.js: 6.5.9
pixi-viewport: 5.0.1
@ahmafi I believe the latest version of pixi-viewport uses pixi.js v7, and it looks like you're using pixi.js v6. Could you try it with 7?
@RJWadley I suppose merging will go faster if you will clean up yarn.lock
changes
can confirm it works for Sveltekit
bump
@RJWadley you should rebase + fix your yarn.lock diff
Merge please!
Bump
Thanks!
Was this released on NPM? I'm on v5.0.2 and I still get errors from the window references.
yeah, looks like this was never published. I think the library would probably benefit a lot from an auto-publish action on push to main.
@davidfig I understand you might be a bit busy, would you like help maintaining pixi-viewport?
Still erroring out around these, had to compile myself
fixes #432