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 6842235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:04:29+00:00 2026-05-27T00:04:29+00:00

Adding player name into list: chatList0.Add(s); Adding player msg into list: chatList.Add(s); Printing the

  • 0

Adding player name into list:

chatList0.Add(s);

Adding player msg into list:

chatList.Add(s);

Printing the player name & msg in different color:

            for (int i = 0; i < chatList0.Count(); i++)
            {
                //draw system msg (contains name/time/etc)
                spriteBatch.DrawString(font, chatList0[i], new Vector2(40, arr1[i]), Color.Yellow);
                //check length of system msg
                Vector2 offset = textEntry.GetMeasurements(font, chatList0[i]);
                //draw msg after offset
                spriteBatch.DrawString(font, chatList[i], new Vector2(offset.X + 40, arr1[i]), Color.White);
            }

Is this correct? Are there any changes needed to optimize the code?

  • 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-05-27T00:04:30+00:00Added an answer on May 27, 2026 at 12:04 am

    DrawString can only draw in one colour at a time, so you need to draw the 2 different bits of text separately.

    I suggest making a class or struct for your messages, that has PlayerName and Message properties.

    Then when you loop through each item to draw them, get the PlayerName, then use SpriteFont.MeasureString to measure how wide the string will be.

    Then draw the PlayerName (and a ": " or whatever) where you currently do.

    Then, draw the Message, in your other colour, offset by the X property of the vector returned from your measurestring method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Adding an element to the head of an alist (Associative list) is simple enough:
I am adding an image into a JLabel and trying to set the width
I'm trying to build a simple music player with a ListBox playlist. When adding
I have a the following chunk of code that's adding up to six Player
I'm adding a small .swf object (XSPF Web Music Player) to a site I'm
I'm trying to convert a string into an int so that I can keep
I'm adding online two player to a game using Game Kit. My test devices
Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere_else/source.cpp, vs. just
Adding more than one child to a WPF StatusBar results in poor layout with
Adding Exceptional Handling is a good practise, but I have a doubt, In our

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.