コード例 #1
0
ファイル: AssetManager.cs プロジェクト: rubna/MetroidClone
 public Font GetFont(string name)
 {
     if (!assets.ContainsKey(name))
     {
         assets[name] = new Font(content.Load<SpriteFont>("Content/" + name));
     }
     return assets[name] as Font;
 }
コード例 #2
0
ファイル: DrawWrapper.cs プロジェクト: rubna/MetroidClone
 public Vector2 MeasureText(Font font, string text)
 {
     return font.Measure(text);
 }
コード例 #3
0
ファイル: DrawWrapper.cs プロジェクト: rubna/MetroidClone
        public void DrawText(string font, string text, Vector2 position, Color? color = null, float rotation = 0f, Vector2? origin = null, float scale = 1f, Font.Alignment alignment = Font.Alignment.TopLeft)
        {
            BeginSpriteBatch();

            DrawText(Assets.GetFont(font), text, position, color, rotation, origin, scale, alignment);
        }
コード例 #4
0
ファイル: DrawWrapper.cs プロジェクト: rubna/MetroidClone
        //Methods to draw text.
        public void DrawText(Font font, string text, Vector2 position, Color? color = null, float rotation = 0f, Vector2? origin = null, float scale = 1f, Font.Alignment alignment = Font.Alignment.TopLeft)
        {
            BeginSpriteBatch();

            Vector2 finalOrigin = origin ?? new Vector2(0f, 0f);

            //Apply the alignment.
            if (alignment != Font.Alignment.TopLeft)
            {
                Vector2 textMeasure = font.Measure(text);
                if (alignment == Font.Alignment.MiddleLeft || alignment == Font.Alignment.MiddleCenter || alignment == Font.Alignment.MiddleRight)
                    finalOrigin.Y += textMeasure.Y / 2;
                if (alignment == Font.Alignment.BottomLeft || alignment == Font.Alignment.BottomCenter || alignment == Font.Alignment.BottomRight)
                    finalOrigin.Y += textMeasure.Y;
                if (alignment == Font.Alignment.TopCenter || alignment == Font.Alignment.MiddleCenter || alignment == Font.Alignment.BottomCenter)
                    finalOrigin.X += textMeasure.X / 2;
                if (alignment == Font.Alignment.TopRight || alignment == Font.Alignment.MiddleRight || alignment == Font.Alignment.BottomRight)
                    finalOrigin.X += textMeasure.X;
            }

            spriteBatch.DrawString(font.SpriteFont, text, position, color ?? Color.Black, rotation, finalOrigin, scale, SpriteEffects.None, 0f);
        }