I'm working on a 2D game. It has tiles. each tile is 50x50 px. I attached script to camera which sets the camera size to screenHeight/2/PixelsPerUnit.
Now in the player, as an example i selected 480x320 size. I expected it to show approx 9x6 tiles. However it shows 6tiles horizontally and 4 tiles vertically.
Similarly for other sizes, it shows lesser than calculated number of tiles.
How does this corelate?
Edit i created the tiles in photoshop with 300 dpi. Not sure if that affects anything though.
Answer
I asked this question when I was an absolute newcomer. Answering this now so someone looking for this finds the solution.
First part of my question was about setting camera size so a certain background fits the screen perfectly, both horizontally and vertically. Now I know that's a bad idea because having a background fit one single size means skybox will show on wider screens.
So, here is what I did. When we set camera size, there's a certain screen height. This height is fixed irrespective of the device screen. On larger devices, greater detail, on smaller devices, lesser detail. So, if I chose 760px as height of my background image, I calculate camera size as follows: cameraSize= (Height/2)/PixelsPerUnit which in my case is, (760/2)/100=3.8
Next, I need to make sure skybox doesn't show irrespective of the device's screen size. This means, design background for the widest aspect ratio which is 16:9. So, I calculated the width as
width=AspectRatio X height. Which in my case is (16/9) X 760=1352 px.
So my background is 1352 X 760 pixel. This fits 16:9 aspect ratio perfectly. On narrower ratios like 4:3, there is cropping towards the sides. But skybox never shows. Which was my main issue.
No comments:
Post a Comment