Sunday, July 21, 2013

Dynamic screen displaying sorted

Last night I was able to sit down and analyse my last screen resizing display bug.

The one I had left was whenever a sprite rotated on the newly sized screen the origin would not be in its center, so making the sprite move around the screen while rotating, a stupid looking bug. Especially when my enemy craft have explosions going off all over them randomly, and those explosions are randomly rotated to give more visual appeal to the explosion animation.

What is the Dynamic Screen Displaying?
Well ok, I don't have a fancy name for it, though I am sure someone has a nice short fancy name when they stuck a flag into the idea. What I am doing is,

My game is designed to run in a fixed resolution (it is a 2d game after all). In this games case I am using the iPad resolution of 768x1024 (portrait mode). So all my graphics and relative sizes are laid out for this resolution. Which is a great thing if you are only going to be on this machine. As it happens I also want my game to work on other devices, and therefore other resolutions.

So saying I want to use a 640x960 (iPhone 4) resolution, I make my game do scaling adjustments to fit this new size. I have an X Scale as well as a Y Scale and they are set by dividing the new resolution by the original one. So in the iPhone4 case the XScale=640/768=0.833f. Then I multiply all my rendering cords by these scales. I also have to scale the size of the image as well.

What this means is only the rendering and a few other systems need to care about the resizing of the screen. The game underneath still works within the original coordinate system. So the players movement still goes from 0 to 768 across the screen. With this visual compensation the game is good, and then I simply have to fix any oddities. For example the cords that I get back from the touch, must also be rescaled back up to the original values.

Good luck, and please realize there are other ways to accomplish this task,

Da Voodoochief

No comments:

Post a Comment