The following event can possibly get called hundreds of times a frame.
public bool OnCollision(Body body1, Body body2) { if(body2.Tag is Dog) ((Dog)body2.Tag).Bark(); }
I understand that using ‘is’ causes a cast to be made and then when i want to do something with it, cast it a second time. Is there a more efficient way to check the type? I made a console app trying ‘if(body2.Tag.GetType() == typeOf(Dog))’ but it appears to be even slower than using ‘is’.
Thanks.
is actually compiled as
In your code, you’re then doing the cast again. Better would be: