C# XNA Texture2D Collision?
I'm currently working on a simple lightning system for an isometric game
and after few hours of thinking I came up with a solution which looks like
this : http://puu.sh/4oHR8.jpg
So , I draw a texture (a simple form like a triangle,circle etc) above the
tiles and I want to check which tiles intersects the image and light them.
The problem is that I don't know how to do it properly.I tried pixel
collision because the tiles are represented by a texture but it didn't
work at all.
Do you have any suggestions which could help me?
Thank you in advance.
Edit This is the code I used for pixel collision.
enter code here
static bool IntersectPixel(Rectangle rect1, Color[] data1,
Rectangle rect2, Color[] data2)
{
int top = Math.Max(rect1.Top, rect2.Top);
int bottom = Math.Min(rect2.Top, rect2.Bottom);
int left = Math.Max(rect1.Left, rect2.Left);
int right = Math.Min(rect1.Right, rect2.Right);
for (int y = top; y < bottom; y++)
{
for (int x = left; x < right; x++)
{
Color color1 = data1[(x - rect1.Left) + (y - rect1.Top) *
rect1.Width];
Color color2 = data2[(x - rect2.Left) + (y - rect2.Top) *
rect2.Width];
if (color1.A != 0 && color2.A != 0)
{
return true;
}
}
}
return false;
}
No comments:
Post a Comment