Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7884179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:43:46+00:00 2026-06-03T04:43:46+00:00

Im working in xna and my problem is the following. I got a text

  • 0

Im working in xna and my problem is the following. I got a text where the first occurence of
” ________ ” should be highlightet for the user in some way. This could be done by making the fontsize of this part bigger, highlighting or some other way if anyone got a great idea.

public void DrawStringWithStyle(SpriteBatch batch, SpriteFont thisFont, Vector2 pos, string thisText, SpriteFont BoldFont)
    {
        string[] paragraphs = Regex.Split(thisText, @"\\(c[a-fA-F0-9]{6})|\\(b)|\\(o)|\\(l)");
        SpriteFont CurrentFont = font;
        float tempPosX = pos.X;

        for (int i = 0; i < paragraphs.Length; i++)
        {
            batch.DrawString(CurrentFont, paragraphs[i], new Vector2(tempPosX, pos.Y), Color.Black);

            if (i + 1 < paragraphs.Length)
            {
                tempPosX += CurrentFont.MeasureString(paragraphs[i]).X;

                i++;

                switch (char.ToLower(paragraphs[i][0]))
                {
                    case 'o': CurrentFont = font; break;
                    case 'b': CurrentFont = BoldFont; break;
                    case 'l':
                        paragraphs[i+1] = paragraphs[i+1].Insert(0, Environment.NewLine);
                        tempPosX = pos.X;
                        break;
                }
            }
        }
    }

So i got 2 new problems as you might be able to tell. One of them is that 2 commands musnt come in a row because then it will screw up bigtime, need to be able to check if the next is a command or if its a normal paragraph somehow. The other problem needs a solution quite like that because my (l) command only works if the following paragraph isnt a command. Any idea on how to fix my 2 problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:43:47+00:00Added an answer on June 3, 2026 at 4:43 am

    Split the text that has different styles… and draw each part with its style.

    You can use a \c to change color: “My \cFF5566favaourite \cFFFFFFgame is \c444444warcraft 3”, or \b to use bold font…

    public static void DrawStringWithStyle( this SpriteBatch batch, SpriteFont font, Vector2 pos, string text, Color color, SpriteFont BoldFont=null )
    {
        string[] paragraphs = Regex.Split( text, @"\\(c[a-fA-F0-9]{6})|\\(b)|\\(n)" );
        Color CurrentColor = color;
        SpriteFont CurrentFont = font;
    
        for ( int i=0; i< paragraphs.Length; i++ )
        {
            batch.DrawString( CurrentFont, paragraphs[i], pos, CurrentColor );
    
            if ( i+1<paragraphs.Length )
            {
                pos.X += CurrentFont.MeasureString( paragraphs[i] ).X;
                i++;
    
                switch (char.ToLower(paragraphs[i][0]))
                {
                    case 'c':
                        CurrentColor.R = byte.Parse( paragraphs[i].Substring( 1, 2 ) );
                        CurrentColor.G = byte.Parse( paragraphs[i].Substring( 3, 2 ) );
                        CurrentColor.B = byte.Parse( paragraphs[i].Substring( 5, 2 ) );
                        break;
                    case 'n': CurrentFont = font; break;
                    case 'b': CurrentFont = BoldFont; break;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on XNA C# when I came upon this problem where I need
I'm working in XNA and I hit the following problem: My goal was to
Hey all, i've been working on this small project in XNA the goal is
I am currently working on some game made in C# XNA. Since I need
I have been working on XNA for quite some time, but was asked to
just joined this awesome site… Ive recently been working in XNA on C#, making
I'm working on my first multiplayer XNA game, and I need to be able
I'm working on a Windows Phone app and am having the following problem. I
I'm working on my First 2D Game with XNA and I have a little
I am working on a game project using Microsoft XNA framework, although this question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.