Reputation: 2435
What i'm trying to do is check perfect-pixel colision with 2 textures which have black edges for example: one of this texture is a circle the second one can be triangle or rectangle.
this my code which give me only array of color without coordinates which i need
Color[] playerColorArray = new Color[texturePlayer.Width * texturePlayer.Height];
Color[] secondColorArray = new Color[secondTexture.Width * sencondTexture.Height];
texturePlayer.GetData(playerColorArray);
secondTexture.GetData(secondTextureArray);
and my question is how to get coordinates from Texture2D for each pixel which are Black in this Texture2D.
thanks for advance:)
Upvotes: 4
Views: 11278
Reputation: 19
Personally I rather write extension methods:
public static class Texture2dHelper
{
public static Color GetPixel(this Color[] colors, int x, int y, int width)
{
return colors[x + (y * width)];
}
public static Color[] GetPixels(this Texture2D texture)
{
Color[] colors1D = new Color[texture.Width * texture.Height];
texture.GetData<Color>(colors1D);
return colors1D;
}
}
Upvotes: 1
Reputation: 1897
You already have array of colors, so only one you need is to determinate coordinate in 2D of each from pixels in your arrays.
in Riemers tutorial (which I recommend), it's done like that:
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];
}
}
Upvotes: 5