XNA/Monogame GraphicsDevice method change? What is proper way to instantiate it?

StackOverflow https://stackoverflow.com/questions/23575473

  •  19-07-2023
  •  | 
  •  

Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top