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。 –