【问题标题】:Draw a string to texture in XNA?在 XNA 中绘制一个字符串到纹理?
【发布时间】:2011-12-08 12:11:40
【问题描述】:

非常简单。我想取一个像“Bananas”这样的字符串,在上面打一个SpriteFont,然后把它渲染到Texture2D,而不是像SpriteBatch允许的那样直接渲染到屏幕上。

我可以这样做吗?或者,我可以使用某种 FBO 式的功能来完成类似的事情吗?

【问题讨论】:

    标签: fonts xna textures


    【解决方案1】:

    您可以使用 RenderTarget2D 类。 http://msdn.microsoft.com/en-us/library/bb198676.aspx 像这样的:

    RenderTarget2D target = new RenderTarget2D(GraphicsDevice, width,height);
    GraphicsDevice.SetRenderTarget(target);// Now the spriteBatch will render to the RenderTarget2D
    
    spriteBatch.Begin();
    
    spriteBatch.DrawString();//Do your stuff here
    
    spriteBatch.End();
    
    GraphicsDevice.SetRenderTarget(null);//This will set the spriteBatch to render to the screen again.
    
    //If you are going to create the render target inside the Draw method, do this:
    target.Dispose();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 2013-05-09
      • 1970-01-01
      相关资源
      最近更新 更多