pixi-viewport
pixi-viewport copied to clipboard
Fitting part of world coordinates to screen by independent scaling
Hi Let's say I have world coordinates => 1000 x 500 and the canvas size is 100 x 100 i.e. the screen coordinates
How do I fit it so that width is scaled by 10% and height by 20% to fit whole screen?
Also, let's say I want to render subset of the world to screen i.e. (100,100) as the starting point with width 300 and height 250. How do I make this rectangle [(100,100), (400,100), (400,350), (100,350)] take up the screen (100x100)?
The viewport can be scaled by axis independently, but I've not done much testing on that scenario since I normally don't scale that way.
The fitWidth()
and fitHeight()
functions should help you. These calculate the viewport scale based on the desired width or height. You can either use these directly, or copy the code so you can do some additional math to get your desired effect.