Question

I had a game I wrote a few months ago and it worked fine. Recently I've updated my Monogame references and now something that compiled and worked before doesn't because the signature's changed on GraphicsDevice, but not sure how best to implement it now. Haven't found any examples yet.

Original line:

var obsticleTexture = new Texture2D(new GraphicsDevice(), 0, 0);

but now I get

'Microsoft.Xna.Framework.Graphics.GraphicsDevice' does not contain a constructor that takes 0 arguments

The signature's changed to:

GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters)

I tried doing new Texture2D(new GraphicsDevice(null, GraphicsProfile.HiDef, new PresentationParameters()),0,0); but that didn't work.

Was it helpful?

Solution

Try this:

GraphicsDevice newGraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, new PresentationParameters());

Texture2D texture = new Texture2D(newGraphicsDevice, 1, 1)

Keep in mind that the width and height of the Texture2D must be > 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top