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

Har*_*9pl 4 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);
Run Code Online (Sandbox Code Playgroud)

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

感谢提前:)

Tha*_*ven 5

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

Riemers 教程(我推荐)中,它是这样完成的:

    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]; 
         }
     }
Run Code Online (Sandbox Code Playgroud)