XNa Chinese support

Source: Internet
Author: User

I don't know if anyone was there.

The written content is similar to that of me, but I can ensure that I come up with my own content! Not plagiarism! Of course, in fact, the content itself is not difficult!

 

Recently, I have been studying C # Game Development and want to find a lot of MDX-related information. I did not expect that there are too few MDX materials! Even if there is English, I cannot understand it!

(I am really not good at English, even if I can barely understand some, it is too hard! I can't stand it anymore !) So I came to the eye again with the three English words "... xNa", mom!

It's her again. I knew there was such a thing nearly a year ago, but I thought xNa was not powerful at the time, so I put it behind me,

And now, ah !..........

It seems that I have to look at it again!

It's great to have a Chinese translation! I'm so happy! So I am very happy, but when I am in full swing! Question! Chinese text output is not supported (I mean display ).................?

 

Depressing. It's so depressing !!!! This is really a pot of cold water for me!

After thinking for a while, do you have drawstring () in GDI + from time to time, but it only supports forms!

Can I apply it to xNa?

After about an hour or two, the Code is as follows: (a little longer, because I am a beginner in C)

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Drawing. drawing2d;
Using system. drawing;
// Using Microsoft. xNa. Framework;
Using Microsoft. xNa. Framework. graphics;
// Using Microsoft. xNa. Framework. Graphics. packedvector;
// Using Microsoft. xNa. Framework. design;
// Using Microsoft. xNa. Framework. gamerservices;
// Using Microsoft. xNa. Framework. Audio;
// Using Microsoft. xNa. Framework. content;
// Using Microsoft. xNa. Framework. gamerservices;
// Using Microsoft. xNa. Framework. Graphics. packedvector;
// Using Microsoft. xNa. Framework. graphics;
// Using Microsoft. xNa. Framework. input;
// Using Microsoft. xNa. Framework. Media;
// Using Microsoft. xNa. Framework. net;
// Using Microsoft. xNa. Framework. storage;

Namespace mychanesesprintfont
{
Public class mychnsprintfont
{

Public mychnsprintfont ()
{

}

/// <Summary>
/// Note that this method is applicable when the game is initialized, because frequent use of the xNa draw method will cause your game performance to decline, in addition, the first parameter is system. drawing; or system. drawing. drawing2d; In the namespace!
/// </Summary>
/// <Param name = "graphics"> get the rendering (or drawing device) device of xNa, for example: graphics. graphicsdevice </param>
/// <Param name = "showstringorfilename"> obtain the string you want to draw. For example, "I am a super dumb ----- Shi Gao, sgf" </param>
/// <Param name = "fontfamily"> obtain the font of the string you want to use, for example, "" </param>
/// <Param name = "fontsize"> obtain the size of the string you want to draw (the size here refers to the font size), for example, 16f </param>
/// <Param name = "myfontstyle"> obtain the string style you want to draw, for example, system. drawing. fontstyle. bold, system. drawing. color. blue </param>
/// <Param name = "myfontcolor"> obtain the color of the string to be drawn, for example: </param>
/// <Param name = "bitmapformat"> obtain the bitmap structure of the image where the string you want to draw resides, for example, system. Drawing. imaging. pixelformat. format24bpprgb. </param>
/// <Returns> Note: The returned value is texture2d. </returns>
Public static texture2d newstring (Microsoft. xNa. framework. graphics. graphicsdevice graphics, string showstringorfilename, string fontfamily, float fontsize, system. drawing. fontstyle myfontstyle, system. drawing. color myfontcolor, system. drawing. imaging. pixelformat bitmapformat)
{
Font font;
Font = new font (fontfamily, fontsize, myfontstyle, graphicsunit. pixel );
Float FX = (font. Size/72) * 96;
Float FY = FX;
Int stringplxlength = (INT) (showstringorfilename. Trim (). Length/2 * FY + showstringorfilename. Trim (). length * FX/5 );
Bitmap bitmap = new Bitmap (stringplxlength + 20, (INT) (FX-FX/5), bitmapformat );
System. Drawing. Color colorkey = bitmap. getpixel (1, 1 );
Graphics G = graphics. fromimage (Bitmap );
Solidbrush sb = new solidbrush (myfontcolor );
G. drawstring (showstringorfilename, Font, Sb, new pointf (0, 0 ));
Bitmap. maketransparent (colorkey );
String filename = showstringorfilename + ". PNG ";
Bitmap. Save (filename );
Texture2d t2d = texture2d. fromfile (graphics, filename );
Return t2d;
}
}
}

 

I declare it again! Because it is a GDI + technology, we recommend that you do not use it frequently in the draw () function. Otherwise, your game performance will be greatly reduced!

In some unnecessary situations, it is best to call the above function when the game is added! Generate texture2d texture,

I inserted a method in the draw () function to check whether the string has changed!

So I called it in the draw () function, but I strictly restricted the number of times, so that there will not be too much performance degradation for the game itself!

Don't blame me for not reminding you!

XNa itself is very powerful and powerful as the successor of MDX, and its performance is much better than that of MDX!

 

If someone reprint please indicate the source http://blog.csdn.net/shigaofei1/archive/2010/04/05/5452619.aspx

This is the debut of the younger brother. Although there is not a high technical level, it is also the income of labor! In addition, please kindly advise and give more advice!

 

 

Preview the image as a result:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.