Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在XNA中对文本实现方法_C#_Text_Xna - Fatal编程技术网

C# 在XNA中对文本实现方法

C# 在XNA中对文本实现方法,c#,text,xna,C#,Text,Xna,所以我今天开始和XNA混在一起,我还在学习C。我正在尝试制作一个游戏的主菜单 我已经制作了一个sprite字体文件,正在生成我想要的文本。这方面的代码是: spriteBatch.DrawString(font, ">://Start Game [1]", new Vector2(0, 0), Color.LimeGreen); 我的问题是我有一种方法从“电脑”打字效果(我几天前问了一个问题),但这是C++。我知道如何将其转换为C#,但即使我正确地转换了代码,如何将该方法应用于正

所以我今天开始和XNA混在一起,我还在学习C。我正在尝试制作一个游戏的主菜单

我已经制作了一个sprite字体文件,正在生成我想要的文本。这方面的代码是:

    spriteBatch.DrawString(font, ">://Start Game [1]", new Vector2(0, 0), Color.LimeGreen);
我的问题是我有一种方法从“电脑”打字效果(我几天前问了一个问题),但这是C++。我知道如何将其转换为C#,但即使我正确地转换了代码,如何将该方法应用于正在创建的文本?用XNA打印文本是否更有效

< C++中的打字效果代码是:

    void typeOutput(string displayString){

        for(int i = 0; i < displayString.length(); i++){

            cout << displayString[i];
            Sleep((rand() + 1)%typeSpeed);

        }
    }
void类型输出(字符串显示字符串){
对于(int i=0;icout中讨论了各种方法。该线程的一个示例是:

// our string will take 3 seconds to appear 
private const float timerLength = 3f; 
private float timer = 0f; 
然后在Draw方法中添加到计时器,并使用该计时器确定要绘制的字符串数量:

timer += (float)gameTime.ElapsedGameTime.TotalSeconds; 

// if the timer is passed timerLength, we just draw the whole string 
if (timer >= timerLength) 
{ 
   spriteBatch.DrawString(myFont, myString, stringPosition, stringColor); 
} 

// otherwise we want to just draw a substring 
else 
{ 
   // figure out how many characters to show based on 
   // the ratio of the timer to the timerLength 
   int numCharsToShow = (int)(myString.Length * (timer / timerLength)); 
   string strToDraw = myString.Substring(0, numCharsToShow);    

   // now just draw the substring instead 
   spriteBatch.DrawString(myFont, strToDraw, stringPosition, stringColor); 
}

非常感谢,我实际上并没有使用这个确切的答案,但我在你链接的网站上找到了一个满足我所有需要的例子:生成文本,使打字效果,并使文本居中。非常感谢!