I'm writing a game in MonoGame and have an entity
class which is used by pretty much every game object. While the entity class doesn't have its own defined texture, having the texture
member declared inside that class would greatly simplify the code by eliminating the need to override certain virtual functions with the exact same code in every child class.
For instance, I currently have to put this in my Entity
class:
public virtual void Draw() { }
and then add this in every single derived class:
public static Texture2D texture;
...
public override void Draw()
{
if (active)
Game1._spriteBatch.Draw(texture, position, Color.White);
}
I tried various things like new static
, but they didn't work. Can someone help, or is it simply not possible in C#? I know I can write a virtual accessor function and override that, but I'd rather not have to write that in every single child class.