1
我有像素完美碰撞下来,但它只能在0弧度旋转质感的作品。这是我确定像素完美的碰撞 -像素完美碰撞纹理旋转
public static bool IntersectPixels(Texture2D sprite, Rectangle rectangleA, Color[] dataA, Texture2D sprite2, Rectangle rectangleB, Color[] dataB)
{
sprite.GetData<Color>(dataA);
sprite2.GetData<Color>(dataB);
// Find the bounds of the rectangle intersection
int top = Math.Max(rectangleA.Top, rectangleB.Top);
int bottom = Math.Min(rectangleA.Bottom, rectangleB.Bottom);
int left = Math.Max(rectangleA.Left, rectangleB.Left);
int right = Math.Min(rectangleA.Right, rectangleB.Right);
// Check every point within the intersection bounds
for (int y = top; y < bottom; y++)
{
for (int x = left; x < right; x++)
{
// Get the color of both pixels at this point
Color colorA = dataA[(x - rectangleA.Left) + (y - rectangleA.Top) * rectangleA.Width];
Color colorB = dataB[(x - rectangleB.Left) + (y - rectangleB.Top) * rectangleB.Width];
// If both pixels are not completely transparent,
if (colorA.A != 0 && colorB.A != 0)
{
// then an intersection has been found
return true;
}
}
}
// No intersection found
return false;
}
我有我的麻烦发生碰撞时,旋转的代码。我将如何去检查像素碰撞与旋转的精灵?谢谢,任何帮助表示赞赏。
你知道你可以借鉴的旋转纹理一个'RenderTardet2D',其转换为'Texture2D',然后核对你的现有的方法。只要知道它可能会拿走大量的CPU来做到这一点。我建议采用更高效,不同的方法,但我不知道。 – user1306322
是的,这就是问题一旦当你载入纹理它不会,如果你将其旋转或缩放工作..检查矩阵旋转......可是,你真的NEET像素的碰撞?这是cpu杀手。更好地使用rectange,圆形甚至多边形collsion。 –