Advice for implementing swords

Topics: User Forum
Mar 7, 2011 at 2:56 AM

I'm currently working on a side scrolling platformer, and have a character carrying a sword, in one sprite.  What's the recommended way to determine whether a collision occurred with the sword or the rest of the body?  Should I break them up into two images?



Mar 7, 2011 at 11:23 AM

You can either have them as separate images using separate bodies or keep them as a single body with multiple fixtures.

Using the in parameters from OnCollision, you can then determine which body (using UserData) / fixture made the contact.

Mar 8, 2011 at 12:05 AM

Right now my code looks along the lines of

var fixture = FixtureFactory.CreateRectangle(m_world, MKS.ToMeters(64), MKS.ToMeters(128), 1);
fixture.Body.BodyType = BodyType.Dynamic;

I see that body has a fixture list that I can add to, but the fixture's Body property is read only.  Will this cause problems?

My next question is how would I break them up.  I was planning on trying out the Texture to Polygon sample.  In this case, I think I'll have to do this twice.  I'm planning to create one texture with the character, one texture with the sword, and one texture with both.  The first two would be used for collision detection, and the third would be used for display.  Is this a reasonable way to do it?  Or is there a better way?