This project has moved and is read-only. For the latest updates, please go here.


May 26, 2009 at 4:13 AM

Ok so I am using the OnCollision and OnSeparation events quite frequently in my code and I am also constantly making use of the .Tag feature. However, I have been tagging everything as strings instead of as objects and as a result, I have no access to the other methods and properties of my classes in the OnCollision method. I have managed to work around this issue however it seems like a much cleaner approach to tag my objects as objects. I have a couple general questions about this practice:

1) I have read that it is quite a performance hit to unbox/box objects every call - if I tag using strings is the performance still hit?

2) How exactly do I tag something as an object?   Ie. Currently in my player class I construct the geom and body etc. then I say playerGeom.Tag = "player". How do I write the tagging line if I wanted to tag the player as the actual player class - or can this only be done when I actually create a new player in the main game class?

May 26, 2009 at 4:43 AM

In my game I simply set the Tag = this (which in your case would be the player class).

May 26, 2009 at 9:40 AM

yeah, just set geom.Tag = this. Tag is of type object so actually there is no boxing. i think you mean casting and that shouldn't hurt, especially with objects. boxing is a technique that puts an elementary type (int, float) or value type (structs) into an object (see Integer class for example).