c# - 如何从Texture2D XNA c#获取颜色和坐标(x,y)?

标签 c# xna xna-4.0

我想要做的是检查具有黑色边缘的 2 个纹理的完美像素碰撞,例如:此纹理之一是圆形,第二个可以是三角形或矩形。

这是我的代码,它只给我颜色数组,没有我需要的坐标

Color[] playerColorArray = new Color[texturePlayer.Width * texturePlayer.Height];
Color[] secondColorArray = new Color[secondTexture.Width * sencondTexture.Height];
texturePlayer.GetData(playerColorArray);
secondTexture.GetData(secondTextureArray);

我的问题是如何从 Texture2D 获取此 Texture2D 中每个黑色像素的坐标。

感谢提前:)

最佳答案

您已经拥有一系列颜色,因此您只需要从阵列中的像素确定每个颜色的 2D 坐标。

Riemers tutorial (我推荐),它是这样做的:

    Color[,] colors2D = new Color[texture.Width, texture.Height];
     for (int x = 0; x < texture.Width; x++)
     {
         for (int y = 0; y < texture.Height; y++)
         {
             colors2D[x, y] = colors1D[x + y * texture.Width]; 
         }
     }

关于c# - 如何从Texture2D XNA c#获取颜色和坐标(x,y)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532919/

相关文章:

c# - 600K 记录的数据库或平面文件?

c# - 哪些单元测试框架以及如何开始(针对 asp.net mvc)

c# - 使用 C# 和查询选择特定条件,将查询拉出的数字( double )相乘

c# - Texture2D 变黑

c# - 非静态字段、方法或属性 'Microsoft.Xna.Framework.Input.MouseState.X.get' 需要对象引用?

c# - C# 中空合并赋值运算符的实际用途?

c# - 如何在XNA中制作精确的时钟?

c# - 2D 游戏引擎中应该包含什么?

c# - XNA 框架 : Manipulating screen brightness

c# - 将 XML 属性与 IntermediateSerializer 一起使用