davidfig / pixi-scrollbox

a scrollbox built for pixi.js using a masked box that scrolls vertically and/or horizontally with optional scrollbars
https://www.npmjs.com/package/pixi-scrollbox
MIT License
170 stars 33 forks source link

Sprites with negative positions not visible in the viewport #37

Closed fix777 closed 3 years ago

fix777 commented 3 years ago

Here is a CodeSandbox. I give 2 Sprites in the CodeSandbox:

davidfig commented 3 years ago

Ah. Scrollbox assumes your top-left corner is 0, 0. The underlying viewport that scrollbox is based on handles negative values fine, it's just the scrollbox calculations for scrollbars and clamping and such that limit the top-left value. It's possible to tweak the code to allow for arbitrary corners, but I currently don't have plans to do so. I'm happy to take a PR if you're interested.

The easiest way to hack it is to normalize your items. Search through the items and find the smallest x and y. If the smallest value is < 0 then add the negative amount to all items.

A more complicated approach that takes into account rotations and such is to find the bounding box of scrollbox.content (the viewport inside the scrollbox), and then change its position by the negative top-left value in the same way. There'll likely be some tweaking necessary for this to work.

Good luck!

fix777 commented 3 years ago

Thanks, David, I will give it a try. Closing for now.