Safe Zone
According to MSDN, "Xbox 360 games should display all text and menu items critical to game play within the inner 80 percent of the x and y resolution for all display modes" (http://msdn.microsoft.com/en-us/library/bb203889.aspx). So how can you know what that area is. First, there's the Safe Area sample on the Creators Club site. Below are also two classes to assist in that.
First is the SafeZone class which allows you quickly compute a Rectangle based on the percentage of the screen you want. So to get the 80% value you should be using, you would pass in .8f as the second parameter. The class also caches the results in a Dictionary for quick retrieval of identical values.
Determining Safe Zone Areas
public static class SafeZone
{
static readonly Dictionary<float, Rectangle> prevValues = new Dictionary<float, Rectangle>();
public static Rectangle GetTitleSafeArea(GraphicsDevice device, float percent)
{
Rectangle retval;
if (prevValues.TryGetValue(percent, out retval))
return retval;
retval = new Rectangle(
device.Viewport.X,
device.Viewport.Y,
device.Viewport.Width,
device.Viewport.Height);
float border = (1 - percent) / 2;
retval.X = (int)(border * retval.Width);
retval.Y = (int)(border * retval.Height);
retval.Width = (int)(percent * retval.Width);
retval.Height = (int)(percent * retval.Height);
prevValues.Add(percent, retval);
return retval;
}
}Safe Zone Game Component
Next is the SafeZoneComponent. This is a drawable game component which will render the safe zone onto your screen. You will see a yellow border in between the 80-90% area and a red border between 90-100% of the screen size. This lets you easily check your rendering.
public class SafeZoneComponent : DrawableGameComponent
{
SpriteBatch spriteBatch;
Texture2D safeZoneTexture;
Texture2D failZoneTexture;
public SafeZoneComponent(Game game)
: base(game)
{
DrawOrder = int.MaxValue;
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
int screenWidth = GraphicsDevice.Viewport.Width;
int screenHeight = GraphicsDevice.Viewport.Height;
safeZoneTexture = new Texture2D(
GraphicsDevice,
screenWidth,
screenHeight,
0,
TextureUsage.None,
SurfaceFormat.Color);
failZoneTexture = new Texture2D(
GraphicsDevice,
screenWidth,
screenHeight,
0,
TextureUsage.None,
SurfaceFormat.Color);
Color[] safePixels = new Color[screenWidth * screenHeight];
Color[] failPixels = new Color[screenWidth * screenHeight];
Rectangle safe = SafeZone.GetTitleSafeArea(GraphicsDevice, .8f);
Rectangle fail = SafeZone.GetTitleSafeArea(GraphicsDevice, .9f);
for (int x = 0; x < screenWidth; x++)
{
for (int y = 0; y < screenHeight; y++)
{
int i = y * screenWidth + x;
safePixels[i] = (safe.Contains(x, y))
? Color.TransparentWhite
: (fail.Contains(x, y))
? new Color(255, 255, 0, 150)
: Color.TransparentWhite;
failPixels[i] = (fail.Contains(x, y))
? Color.TransparentWhite
: new Color(255, 0, 0, 150);
}
}
safeZoneTexture.SetData(safePixels);
failZoneTexture.SetData(failPixels);
base.LoadContent();
}
public override void Draw(GameTime gameTime)
{
spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
spriteBatch.Draw(safeZoneTexture, Vector2.Zero, Color.White);
spriteBatch.Draw(failZoneTexture, Vector2.Zero, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}