Hi.
I'm trying to get SFML.NET working with Box2DX.
I'm making a simple pong game, and only need to use collision detection and collision callbacks from Box2DX.
I have overridden ContactListener with my own, and it is working fine. The problem is that when I use body.SetUserData() and pass in Sprite object from SFML.NET, I have no idea how I can compare which Sprites collide.
This is what I have now, and it isn't working:
This always prints "Different sprites colliding" when a contact is added, even when the sprites are same.
I want to pass in Sprite object, because I need to draw the sprites using GetUserData().
EDIT:
I also posted a question on Stackoverflow.com.
http://stackoverflow.com/questions/23159713/setuserdata-and-object-comparing-confusion
I'm trying to get SFML.NET working with Box2DX.
I'm making a simple pong game, and only need to use collision detection and collision callbacks from Box2DX.
I have overridden ContactListener with my own, and it is working fine. The problem is that when I use body.SetUserData() and pass in Sprite object from SFML.NET, I have no idea how I can compare which Sprites collide.
This is what I have now, and it isn't working:
Code: Select all
class MyContactListener : ContactListener
{
public override void Add(ContactPoint point)
{
Sprite spriteA = (Sprite)point.Shape1.GetBody().GetUserData();
Sprite spriteB = (Sprite)point.Shape2.GetBody().GetUserData();
if (spriteA == spriteB || spriteB == spriteA)
Console.WriteLine("Same sprites colliding.");
else
Console.WriteLine("Different sprites colliding.");
}
public override void Persist(ContactPoint point) { }
public override void Remove(ContactPoint point) { }
public override void Result(ContactResult point) { }
}
This always prints "Different sprites colliding" when a contact is added, even when the sprites are same.
I want to pass in Sprite object, because I need to draw the sprites using GetUserData().
EDIT:
I also posted a question on Stackoverflow.com.
http://stackoverflow.com/questions/23159713/setuserdata-and-object-comparing-confusion