It isn't that it doesn't work but it isn't working fully. For example if I got enough sprites on the screen it can miss collisions for some odd reason. So far I know it is in the collision code itself.
Here.
public Boolean HasCollided(TreeAbleSFMLSprite otherrect)
{
return this.GetGlobalBounds().Intersects(otherrect.GetGlobalBounds());/* ||
(this.ThisContains(otherrect) || otherrect.ThisContains(this))*/
}
public Boolean ThisContains(TreeAbleSFMLSprite otherrect)
{
return this.GetGlobalBounds().Contains(otherrect.GetGlobalBounds().Left, otherrect.GetGlobalBounds().Top) ||
this.GetGlobalBounds().Contains(otherrect.GetGlobalBounds().Left + otherrect.GetGlobalBounds().Width, otherrect.GetGlobalBounds().Top) ||
this.GetGlobalBounds().Contains(otherrect.GetGlobalBounds().Left, otherrect.GetGlobalBounds().Top + otherrect.GetGlobalBounds().Height) ||
this.GetGlobalBounds().Contains(otherrect.GetGlobalBounds().Left + otherrect.GetGlobalBounds().Width, otherrect.GetGlobalBounds().Top + otherrect.GetGlobalBounds().Height);
}
and here
private void RecursiveCollisionQuadCheck(QuadTree<TreeAbleSFMLSprite> tree, int depth)
{
maxdepth = 0;
if (tree != null)
{
RecursiveCollisionQuadCheck(tree.RootQuad, depth);
}
}
private void RecursiveCollisionQuadCheck(QuadTreeNode<TreeAbleSFMLSprite> node, int depth)
{
if (node != null)
{
if (node.TopLeftChild == null && node.TopRightChild == null && node.BottomLeftChild == null && node.BottomRightChild == null)
{
if (node.Objects != null)
{
foreach (var item in node.Objects)
{
if (item != null && item.Data != null)
{
foreach (var item2 in node.Objects)
{
if ((item2 != null && item.Data != null) && (!item.Equals(item2) && !item.Data.Equals(item2.Data)))
{
item.Data.ColoredCollisions(item2.Data);
item2.Data.ColoredCollisions(item.Data);
}
}
}
}
}
//node.Objects
}
maxdepth = Math.Max(maxdepth, depth);
RecursiveCollisionQuadCheck(node.TopLeftChild, depth + 1);
RecursiveCollisionQuadCheck(node.TopRightChild, depth + 1);
RecursiveCollisionQuadCheck(node.BottomLeftChild, depth + 1);
RecursiveCollisionQuadCheck(node.BottomRightChild, depth + 1);
}
}
If enough sprites get on the screen it starts missing checks or if it gets them.
Here's what it looks like. Most of the green visible should be red but isn't.
I'm starting to think it has more to do with the quadtree not reallocating the sections but not sure but here's what it looks like if I use the two for loop checking.
private void LoopTLoopCollision()
{
foreach (var item in spritelist)
{
if (item != null)
{
foreach (var item2 in spritelist)
{
if ((item2 != null) && (!item.Equals(item2)))
{
item.ColoredCollisions(item2);
item2.ColoredCollisions(item);
}
}
}
}
}
There are several places it should be checking and showing red but isn't for some reason.