Dynamic events

Mar 18, 2011 at 12:04 AM

Hi,

 

Sorry if this is a noobish question...

 

I have a simple game level in .txt format, as I run through the .txt file I pick characters that represent fixtures and add them to a List<Fixture>.

Does anyone know how to dynamically create OnCollision events for each fixture in my list so that I can easily detect collisions between items in the List?

 

I am unable to hard code my game levels as I want the game to be able to use maps with different numbers of fixtures.

Mar 18, 2011 at 3:08 AM

Maybe you could use the characters in your .txt file to represent objects instead of fixtures,

so when your game reads the character, it creates the relevant object and creates the fixtures and the OnCollision events in that objects class (assuming the event is always the same).

After it is loaded you can then add the objects fixture to the List<Fixture>, maybe by giving your objects a GetFixture method that returns the created fixture.

Is this close to what you are looking for?

Regards,

Nick

Mar 18, 2011 at 8:33 AM

Ah yes thank you Nick.

At the moment I have 3 different types of fixture, wall, player and enemy. I will create a class for each of the 3 which will contain the fixture and OnCollision event then create a List of objects. I Don't know why I didn't think of this before.