Comments (8)
Try out v3.4.0. You need to set the PIXI.interaction in the Viewport options:
new Viewport({ interaction: renderer.plugins.interaction })
where renderer = your instantiated PIXI.WebGLRenderer or PIXI.CanvasRenderer
Let me know if this helps.
from pixi-viewport.
Can you provide more info on your set up. I just demoed the following setup (slightly altering the demo code in docs/) and everything worked as I expected w/r/t the offsets:
let _renderer, _viewport
const WIDTH = 1000, HEIGHT = 1000
function renderer()
{
_renderer = new PIXI.Application({ width: 300, height: 300 })
document.body.appendChild(_renderer.view)
_renderer.view.style.position = 'fixed'
_renderer.view.style.width = '300px'
_renderer.view.style.height = '300px'
_renderer.view.style.left = '100px'
_renderer.view.style.top = '100px'
}
function viewport()
{
_viewport = _renderer.stage.addChild(new Viewport())
_viewport
.drag({ clampWheel: true })
.wheel()
.pinch()
.decelerate()
.bounce()
.on('clicked', (e) => console.log('clicked (' + e.world.x + ',' + e.world.y + ')'))
resize()
}
function resize()
{
_renderer.renderer.resize(300, 300)
_viewport.resize(300, 300, WIDTH, HEIGHT)
}
renderer()
viewport()
from pixi-viewport.
I hav the same effect on zooming.
Cause handleWheel use clientX and clientY without the offset. handleWheel think its outside the viewport.
My solution is overriting the handleWheel method, here with typescript
export class MyViewport extends Viewport {
offsetX = 0;
offsetY = 0;
handleWheel(e: WheelEvent) {
const newClientX = e.clientX - this.offsetX;
const newClientY = e.clientY - this.offsetY;
return super.handleWheel(<WheelEvent>{
clientX: newClientX,
clientY: newClientY,
deltaX: e.deltaX,
deltaY: e.deltaY,
preventDefault: () => e.preventDefault()
});
}
}
from pixi-viewport.
handlewheel() is outside pixi.js since they don't support wheel events (for reasonably valid reasons). In your solution, where are you setting this.offsetX/Y?
from pixi-viewport.
before I set the offset in a central positon. But now I have an application where the canvas is inside an Scroller so this solution set offset onetime do not work any more.
My new solution is to inject the canvas Element (view) and get the offset from there:
handleWheel(e: WheelEvent) {
const clientRect = this.view.getBoundingClientRect();
const offsetX = clientRect.left;
const offsetY = clientRect.top;
const newClientX = e.clientX - offsetX;
const newClientY = e.clientY - offsetY;
...
from pixi-viewport.
Hey,
this is working well.
Thank you!
from pixi-viewport.
Closing this. I'll update the documentation to try to call out this option more clearly.
from pixi-viewport.
I had a similar issue, my library depended on pixi-viewport@5 as a peer, but had pixi-viewport@4 in the consuming project
(which caused the viewport to start without a reference to interactions as we now pass the events instead).
upgrading to pixi-viewport@5 in the consuming project fixed this of course
from pixi-viewport.
Related Issues (20)
- failed to import @pixi/core and @pixi/display HOT 1
- Problem with viewport.destroy() when React component gets dismounted HOT 3
- `import "pixi-viewport"` won't import properly in NextJS HOT 5
- Can multiple viewports share events?
- Will it support V8 version? HOT 7
- Pixi Viewport v5.2 release for Pixi v7 HOT 4
- Question: How to use Cmd+Scroll for zooming when on a Mac?
- [Docs] Suggestion: keep Jsdocs in npm package?
- "clicked" event failed to be triggered
- Missing event property from IViewportOptions HOT 3
- NPM Release Version Mismatch HOT 6
- `TypeError: Cannot set properties of undefined (setting '_parentID')` HOT 3
- Version 5.1.0 on NPM is not the same as 5.1.0 on GitHub HOT 6
- Update examples for pixi v8 HOT 6
- Is this project suitable for @pixi/react? HOT 1
- dragging stops when mouse goes over interactive object HOT 1
- Pinch not working correctly in iframe HOT 1
- Drag Plugin Gaps: check for CMD(meta) key to avoid page scrolling HOT 1
- toWorld() not working
- iOS: Viewport not responding when app comes from background to foreground state HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixi-viewport.