我想要做的是检查具有黑色边缘的 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/