Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:36:52+00:00 2026-06-09T22:36:52+00:00

I’m making an xna game and there is going to be many classes that

  • 0

I’m making an xna game and there is going to be many classes that control the drawing and updating and such.

These classes need to be able to access the instance of the original Game1 class, so they can control the graphics device and sprite batch and stuff.

The problem is that I am going to have a network of classes, classes that call other classes, and the classes at the very bottom of the chain still need to be able to access the Game1 class for the graphics device and such.

What is the best way to do this? Just keep passing along the Game1 as a parameter, or what?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:36:53+00:00Added an answer on June 9, 2026 at 10:36 pm

    The “correct” answer from a software engineering/architecture perspective is to pass the specific resources you need as parameters into your methods. This provides many advantages – probably the greatest of which is that it decouples the various parts of your code, allowing them to be used independently of each other.

    To give you an example: You might have your game. But then you might want to take your same code and make an editor, or unit tests, or any manner of other crazy tools. In many of these cases you might not even have a Game class. (To give you a concrete example, this video of mine shows you two very different ways of running the same game code – this would not be possible without proper decoupling.)

    (On this basis, you should probably pass around more specific things than a class derived from Game.)

    You can go a step further, if you have fairly open versioning/dependency requirements, and pass around an IServiceProvider (for example, this is what XNA passes to the constructor of ContentManager). I did a detailed analysis of why you might do this in this answer.

    HOWEVER

    You are not writing a library that will be used by third parties. You are writing a game. The only people who will be using your code are your own team – and you have access the source code and you can freely modify it.

    This means that you are free to take some shortcuts.

    In practice it is usually fine to grab a static instance of your game class, or (and this is my preferred method when I am throwing something together) static properties of your game class. And in XNA you know that you will only ever have a single instance of the game class in practice.

    It is quick and easy to do this in the first place. And it is also quick and easy to go in later on and switch to doing thing the “right” way. As long as you are prepared for it. Good version control and using “Find All References” in Visual Studio are particularly helpful here.

    Basically: as long as you understand that you are taking a shortcut, why you are taking it, and what the “correct” way is – then it is ok to take that shortcut.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.