FlatRedBall Camera Z Position WP7
If you are using a 3D camera in FlatRedBall on WP7, and want your sprites to be pixel-perfect at Z = 0, you might get a little confused. The default camera Z is 40 in FlatRedBall. If you set your sprite scale to be pixel perfect (scale = 0.5f), then a small sprite will take up the entire screen. This is because the screen dimensions in pixels when the camera Z = 40 is roughly 33 x 20. The desired resolution is probably 800×400. So, what should the Camera’s Z position be for pixel-perfect screen dimensions (one screen unit = one pixel at Z = 0)?
It’s simple algebra: first, you can find the Y screen dimension by examining the value of SpriteManager.Camera.AbsoluteTopYEdgeAt(0) when Camera Z = 40. This will tell you what one-half the screen dimension is because 0,0 is in the center of the screen. Using this, I can tell you that the Y dimension of the screen is 16.56854 (assuming vertical orientation) with the camera Z at 40. From there it’s just simple algebra to find the relationship “r” between Z and Y:
40 = 16.56854r r = 40/16.56854 r = 2.4142139259101888277422150654192
So, I want Y to be 400 since my screen resolution is 800. So, we know the relationship and Y, we need Z:
z = 400 * 2.4142139259101888277422150654192 z = 965.68557036407553109688602616766
I use 965.68557 and it seems to be close enough to avoid any artifacts.
UPDATE:
Here’s a TL;DR method you can use in your main Game class:
private float PixelPerfectCameraZ() {
float startingZ = SpriteManager.Camera.Z;
float dimensionY = SpriteManager.Camera.AbsoluteTopYEdgeAt(0);
float ratio = startingZ / dimensionY;
float newZ = (graphics.PreferredBackBufferHeight / 2) * ratio;
return newZ;
}