Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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#_Windows_Xna_Xna 4.0 - Fatal编程技术网

C# 使用XNA中的模板绘制圆形纹理

C# 使用XNA中的模板绘制圆形纹理,c#,windows,xna,xna-4.0,C#,Windows,Xna,Xna 4.0,我正在尝试制作一个基于XNA的小游戏,我需要能够在屏幕周围的多个移动圆圈内绘制一个纹理,就好像它们是“聚光灯”,显示出更大画面的一部分。 在寻找如何做到这一点的过程中,我发现模板可能可以帮助我实现这一点,但我不知道如何使用模板来实现这一点。 如果有人对我如何做到这一点有任何信息或想法,我将非常感激 编辑:我忘了提到游戏是2D的。首先,你需要一个所需模具形状的网格,在本例中是一个圆。XNA不支持许多基本体,因此需要用三角形近似圆 接下来,将渲染该网格,使其几乎与法线相同,但使用: graphics

我正在尝试制作一个基于XNA的小游戏,我需要能够在屏幕周围的多个移动圆圈内绘制一个纹理,就好像它们是“聚光灯”,显示出更大画面的一部分。 在寻找如何做到这一点的过程中,我发现模板可能可以帮助我实现这一点,但我不知道如何使用模板来实现这一点。 如果有人对我如何做到这一点有任何信息或想法,我将非常感激


编辑:我忘了提到游戏是2D的。

首先,你需要一个所需模具形状的网格,在本例中是一个圆。XNA不支持许多基本体,因此需要用三角形近似圆

接下来,将渲染该网格,使其几乎与法线相同,但使用:

graphics.DepthStencilState.DepthBufferFunction = CompareFunction.Never;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilPass = StencilOperation.Replace;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilFunction = CompareFunction.Equal;
现在你有了一个有洞的模板

然后,通过模具渲染纹理,使用正常设置,但使用:

graphics.DepthStencilState.DepthBufferFunction = CompareFunction.Never;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilPass = StencilOperation.Replace;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilFunction = CompareFunction.Equal;
有关更多信息,请参阅的参考


这是基于我的3D知识。如果你想使用精灵,你可能需要做更多的事情。

首先,你需要一个符合所需模具形状的网格,在本例中是一个圆。XNA不支持许多基本体,因此需要用三角形近似圆

接下来,将渲染该网格,使其几乎与法线相同,但使用:

graphics.DepthStencilState.DepthBufferFunction = CompareFunction.Never;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilPass = StencilOperation.Replace;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilFunction = CompareFunction.Equal;
现在你有了一个有洞的模板

然后,通过模具渲染纹理,使用正常设置,但使用:

graphics.DepthStencilState.DepthBufferFunction = CompareFunction.Never;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilPass = StencilOperation.Replace;
graphics.DepthStencilState.StencilEnable = true;
graphics.DepthStencilState.ReferenceStencil = 1;
graphics.DepthStencilState.StencilFunction = CompareFunction.Equal;
有关更多信息,请参阅的参考


这是基于我的3D知识。如果你想使用精灵,你可能需要做更多的事情。

我忘了提到我正在使用2D游戏。这些也适用于2D吗?是的,我想是的。不过,我不确定是否要渲染到模具缓冲区。那可能需要一些3D代码。我明白了。。。我会继续调查,并努力让它与我所拥有的工作。谢谢这回答了你的问题吗?如果有,请检查它作为答案,这样人们就知道问题得到了回答。我忘了提到我正在使用2D游戏。这些也适用于2D吗?是的,我想是的。不过,我不确定是否要渲染到模具缓冲区。那可能需要一些3D代码。我明白了。。。我会继续调查,并努力让它与我所拥有的工作。谢谢这回答了你的问题吗?如果有,请检查它作为答案,这样人们就知道问题得到了回答。