Is it possible to create a transparent messagebox (rectangle) that can write multiple-line text on it?
Is it possible to create a transparent messagebox (rectangle) that can write multiple-line text
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Andy’s solution will suffice, but it might take a few tries until you find the transparency you’re after and it also involves creating and loading a new resource in your program. Fortunately you can avoid this and can make the process configurable by generating a single transparent pixel at runtime which will stretch to the bounds of the
Rectangleargument in theSpriteBatch.Draw(Texture2D, Rectangle, Nullable<Rectangle>, Color)call:Now use the new
texturevariable in your draw call.As for multi-line text, there is a
SpriteBatch.DrawString()overload that accepts a StringBuilder argument. Meaning you can in theory go:I’ll give you another hint that will help you determine the size of the drawing rectangle for the texture:
You can then create a
Rectanglefrom this information, and even give it some padding:Then put everything in to the draw call, including what color to draw the window
The result is a little nicer looking, more automated, and configurable. You should be able to wrap all this stuff in to a re-usable configurable class for your notification messages.
Note: anything other than drawing code should be in LoadContent() or somewhere else, not the actual game’s Draw() call.
Pardon any syntactical errors, I’ve just wrote it off the top of my head.. 🙂