I have a problem where i have a list of one class (DrawableGameComponent) with many instances of different types of classes inherited from DrawableGameComponent.
The thing is i want to access a variable from one of those classes, but since they are declared as a DrawableGameComponent, i can’t access any other variable than DrawableGameComponent has.
main class:
List<DrawableGameComponent> entities = new List<DrawableGameComponent>();
“player” class:
public Color color;
public int score;
any idea of how i can access these variables from the main class?
If
DrawableGameComponentis base forPlayeryou can do this:Beacause ‘is’, ‘as’ and casting are relatively expensive it is preferred to do it just once – as above.