XNA 在运行时在 Texture2D 上绘制/绘制

发布于 2024-11-25 10:55:03 字数 374 浏览 1 评论 0原文

早上好(如果你所在的地方是早上)

我一直在环顾四周,没有找到令人满意的方法,所以我想我会四处询问......

理想的世界我希望能够生成一个透明的Texture2D对象。将其绘制到屏幕上我希望能够“绘制”它,即当鼠标左键按下时,光标所在的任何像素都应设置为黑色。接下来我需要能够使用这个纹理。

使用纹理是最简单的部分,我们可以简单地为“绘画”对象创建一个新的Texture2D属性,并在SpriteBatch.Draw方法中使用它。两个棘手的部分是

  1. 生成指定大小的texture2D对象,并在代码中填充透明度。
  2. 动态编辑texture2D(即能够改变像素颜色)

如果有人对您输入的这些有任何经验,我们将非常感激。

Morning all (if its morning where you are)

I have been looking around and have not seen a satisfactory method for doing this so thought I would ask around...

Ideal world I would like to be able to generate a transparent Texture2D object. Drawing this to the screen I would like to be able to "paint" to it, i.e. when the left mouse button is down whatever pixel the cursor is over should be set to black. Following this I would then need to be able to use this texture.

Using the texture is the easy part, we can simply make a new Texture2D attribute for a "painting" object and use that in the SpriteBatch.Draw method. The two tricky parts are

  1. Generating a texture2D object of a specified size, filled with transparency in code.
  2. Editing that texture2D on the fly (i.e. being able to alter pixel colours)

If anyone has any experience of these you input would be very much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁把谁当真 2024-12-02 10:55:03

您可以使用 RenderTarget2D (MSDN ),它本身就是一个 Texture2D (因此您可以在 SpriteBatch.Draw 中使用它)。这允许您以与渲染到屏幕上相同的方式渲染到纹理上。您需要使用 GraphicsDevice.SetRenderTarget (MSDN) 进行设置。

或者您可以使用Texture2D.SetData (MSDN) 直接操作像素。您可以直接构建透明的Texture2DMSDN)。不要忘记处置您自己创建的任何纹理或其他资源!

You can either use a RenderTarget2D (MSDN), which is itself a Texture2D (so you can use it in SpriteBatch.Draw). This allows you to render onto a texture in the same way you render onto the screen. You need to use GraphicsDevice.SetRenderTarget (MSDN) to set this up.

Or you can use Texture2D.SetData (MSDN) to manipulate pixels directly. You can construct a transparent Texture2D directly (MSDN). Don't forget to Dispose of any textures or other resources you create yourself!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文