C# - Developing Menu for XNA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nicmck34
    New Member
    • Nov 2006
    • 4

    C# - Developing Menu for XNA

    Hi,

    I'm having a problem developing a menu for a XNA project. I'm relatively new to C#.

    The error that I'm getting is:

    'Microsoft.Xna. Framework.Graph ics.GraphicsDev ice' is a 'type' but is used like a 'variable'

    My class that has this error looks like this:

    public override void LoadContent()
    {
    if (content1 == null)
    content1 = new ContentManager( ScreenManager.G ame.Services, "Content");
    spriteBatch = new SpriteBatch(GraphicsDevice); -->This is where I get the error

    myModel = content.Load<Mo del>("Models\\p 1_wedge");
    aspectRatio = (float)graphics .GraphicsDevice .Viewport.Width /
    (float)graphics .GraphicsDevice .Viewport.Heigh t;


    //gameFont = content.Load<Sp riteFont>("game font");
    // A real game would probably have more content than this sample, so
    // it would take longer to load. We simulate that by delaying for a
    // while, giving you a chance to admire the beautiful loading screen.
    //Thread.Sleep(10 00);

    // once the load has finished, we use ResetElapsedTim e to tell the game's
    // timing mechanism that we have just finished a very long frame, and that
    // it should not try to catch up.
    //ScreenManager.G ame.ResetElapse dTime();

    }

    Please help
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You need to create an instance of the GraphicsDevice to pass in.
    It would be like passing the word int in a function instead of say 42.
    So create an instance of that type (possibly a derrived type) and then pass that in.

    Comment

    • airl08
      New Member
      • Sep 2012
      • 1

      #3
      You have to initialize the Device Graphics Manager:
      Code:
      SharedGraphicsDeviceManager graphics = SharedGraphicsDeviceManager.Current;
      and then passing the Graphics Device to the spriteBatch:
      Code:
      spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
      This is for Windows Phone, I guess is the same for Xbox.

      Comment

      Working...