Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Attempting to draw from another class not working

$
0
0

@FLy1nRabBit wrote:

So I'm attempting to call a draw method from another class called Start.cs in my Game1.cs but I keep getting this error:

Here's the code in the Game1.cs:

SpriteBatch spriteBatch;
Texture2D texture;

public Main()
{
	graphics = new GraphicsDeviceManager(this);
	graphics.PreferredBackBufferWidth = 1024;
	graphics.PreferredBackBufferHeight = 576;
	Content.RootDirectory = "Content";
}

protected override void Initialize()
{
	base.Initialize();
}

protected override void LoadContent()
{
	start.LoadContent();
}

protected override void UnloadContent()
{
}

protected override void Update(GameTime gameTime)
{
}

protected override void Draw(GameTime gameTime)
{
	GraphicsDevice.Clear(Color.CornflowerBlue);
	start.Draw(spriteBatch, texture);
}

Here's the code in Start.cs:

SpriteBatch spriteBatch;
Texture2D texture;

public void LoadContent()
{
	spriteBatch = new SpriteBatch(GraphicsDevice);
	texture = Content.Load<Texture2D>("Art/Background/titleimg");
}

public void Draw(SpriteBatch spriteBatch, Texture2D texture)
{
	spriteBatch.Begin();
	spriteBatch.Draw(texture, new Rectangle(0, 0, 1024, 576), Color.White);
	spriteBatch.End();
}

I've tried making a graphicsDevice as a method parameter but that didn't work, and I couldn't find a solution to the problem after searching for a bit. Some help would be appreciated, I imagine it's something simple I keep overlooking.

Thanks.

Posts: 5

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles