pixi-viewport icon indicating copy to clipboard operation
pixi-viewport copied to clipboard

Fitting part of world coordinates to screen by independent scaling

Open krnbatta opened this issue 4 years ago • 1 comments

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)?

krnbatta avatar Mar 07 '20 16:03 krnbatta

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.

davidfig avatar Mar 09 '20 23:03 davidfig