I tried to make a collision box visible (for testing) with spriteBatch.Draw(with a blank texture) in my TileSprite class. I needed a GraphicsDevice for this so these are my variables:
Texture2D blankTexture;
GraphicsDevice GraphicsDevice;
I used this code as my LoadContent():
public void LoadContent()
{
blankTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
Color[] color = new Color[1];
color[0] = Color.White;
blankTexture.SetData(color);
}
I have one TileSprite constructor in my TileSprite class which looks like this (NOTE: this constructor is partially taken from another abstract class, named Sprite):
public TileSprite(GraphicsDevice gd, Texture2D textureImage, Vector2 position, Point frameSize, Point currentFrame)
: base (gd, textureImage, position, frameSize, currentFrame)
{
GraphicsDevice = gd;
bCollisionRect = new Rectangle((int)position.X, (int)position.Y, frameSize.X, frameSize.Y);
}
And then I use this code in my Draw method to draw the box:
spriteBatch.Draw(blankTexture, bCollisionRect, Color.White);
And I have another line of code in the Game1 : Game class (variables like textureImage are written as variables in the beginning of the Game1 class):
tileSprite = new TileSprite(this.GraphicsDevice, textureImage, position, frameSize, currentFrame);
I tested this and I saw that my GraphicsDevice was returning null on a new TileSprite that used a GraphicsDevice from DrawableGameComponent.
SpriteManager : DrawableGameComponentclass are fromDrawableGameComponent\$\endgroup\$GraphicsDeviceis returningnull? \$\endgroup\$