davidfig / pixi-viewport

A highly configurable viewport/2D camera designed to work with pixi.js
https://davidfig.github.io/pixi-viewport/
MIT License
1.04k stars 174 forks source link

Dragging in one direction at a time #454

Closed eivindstr closed 1 year ago

eivindstr commented 1 year ago

Hello! Is it possible to limit the viewport to dragging in the x-direction when pressing one button, and limit it to y-direction when holding a different button? Eventually just making it impossible to drag in both x and y direction at the same time by looking at the initial dragging direction and choosing x/y based on that? I want to be able to drag in both directions, just not at the same time.

davidfig commented 1 year ago

The easiest way is to change the drag() plugin based on keypresses. In your keyboard listener, call viewport.drag({ direction: 'x' }) or 'y' based on the ky.

eivindstr commented 1 year ago

Ok, so it is okay to call the drag plugin multiple times?

davidfig commented 1 year ago

Yes. Recalling a plugin replaces the old one.

eivindstr commented 1 year ago

Thanks!