Layout class that supports title safe area.
You have to support various resolution when you develop multi-platform games. Also, you have to support title safe area for Xbox 360 games. This structure places given rectangle with specified alignment and margin based on layout area (client area) with safe area. Margin is parcentage of client area size. Exmpale: Place( region, 0.1f, 0.2f, Aligment.TopLeft ); Place region at 10% from left side of the client area, 20% from top of the client area. Place( region, 0.3f, 0.4f, Aligment.BottomRight ); Place region at 30% from right side of client, 40% from the bottom of the client area. You can individually specify client area and safe area. So, it is useful when you have split screen game which layout happends based on client and it takes carea of the safe at same time.
Example #1
0
        public override void Draw( GameTime gameTime )
        {
            sampleFrames++;

            SpriteBatch spriteBatch = debugManager.SpriteBatch;
            SpriteFont font = debugManager.DebugFont;

            // Compute size of borader area.
            Vector2 size = font.MeasureString( "X" );
            Rectangle rc =
                new Rectangle( 0, 0, (int)( size.X * 14f ), (int)( size.Y * 1.3f ) );

            Layout layout = new Layout( spriteBatch.GraphicsDevice.Viewport );
            rc = layout.Place( rc, 0.01f, 0.01f, Alignment.TopLeft );

            // Place FPS string in borader area.
            size = font.MeasureString( stringBuilder );
            layout.ClientArea = rc;
            Vector2 pos = layout.Place( size, 0, 0.1f, Alignment.Center );

            // Draw
            spriteBatch.Begin();
            spriteBatch.Draw( debugManager.WhiteTexture, rc, new Color( 0, 0, 0, 128 ) );
            spriteBatch.DrawString( font, stringBuilder, pos, Color.White );
            spriteBatch.End();

            base.Draw( gameTime );
        }
Example #2
0
        protected override void LoadContent()
        {
            Width = (int)( GraphicsDevice.Viewport.Width * 0.8f );

            Layout layout = new Layout( GraphicsDevice.Viewport );
            position = layout.Place( new Vector2( Width, BarHeight ),
                                                    0, 0.01f, Alignment.BottomCenter );

            base.LoadContent();
        }