what is the best way to handle camera for 2d games?

i started 2d game development my graphic resolution is 960*640 i set the same resolution in editor in gam view every thing is fine but when i change resolution or play game on device blue area appear on both left and right side…plz help

This issue is caused by the difference in whats called “Aspect Ratio” which is the relationship between the width and height of the display. Your camera has to project based on the display size meaning that if the screen size increased but maintained the same aspect ratio then all would be fine, but the second that the width or height of the screen changes more or less it can mean that the ratio of width to height is now different, and so the camera will show more things on the left and right of the screen.

There are various approaches people take to try and address this, the simplest is to simply cover it up, position large black covers over the two sides of the screen so that no matter what the display aspect is, you only see the stuff you would see in your 960x640 window. However this is a bit dull and wastes screen space.

I personally prefer the approach where you extend your content to fit a wider aspect ratio, and then either have content dynamically adjust its position relative to the screen (so UI elements anchor to corners etc). Or simply position all of your key content within that 960x640 window so that whilst you are showing things outside that space, the game is still playable when that space is not visible on different aspect ratios.

I hope this helps explain a bit why this is happening. Sorry I can’t go into more detail about how you can setup your content to adjust for aspect ratios, but I’m about to eat.

How did you solve the problem sir ? :slight_smile:
2 weeks of searching, and i still can’t get it on.