Determine how much cropped
Jaytee
Member Posts: 79
Hey there,
I need a way to fix my game so it works on any device (also android). And i think i've come up with a method. But it requires a way to determine how many pixels there is cropped of in height and width. Is there a way to do this??
- Jaytee
I need a way to fix my game so it works on any device (also android). And i think i've come up with a method. But it requires a way to determine how many pixels there is cropped of in height and width. Is there a way to do this??
- Jaytee
Comments
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Take the width/height aspect ratio of the screen that you are currently building in. e.g. if you start in iPad landscape, it is 1024/768 = 1.333333
Then take your target aspect ratio of your current screen size by using the game.Screen.Size.Width/game.Screen.Size.Height aspect ratio.
if your original aspect ratio is smaller than the target aspect, you will be cropping from the top and bottom. If the original aspect ratio is greater, you will be cropping from the left and right.
So in the first case of cropping off the top and bottom, you know that all of the old width will be shown, and you just need to find the new width. To do this you need to normalize the new aspect ratio to the original width and you will find the new height.
So for example, starting with an ipad and going to iphone 5.
1024/? = game.Screen.Size.Width/game.Screen.Size.Height = 568/320
? = 1024*320/568=576.9
So of the original 768, only 576.9 will be seen.
The difference is ~191.1, so half of that is cropped from the top and bottom.
I use this method in the Sod of War Template to adjust the UI buttons as needed. Note: In that template, there is a game attribute that needs to be turned on to allow CropUniversalBuild.