A question about DrawableGameComponent and Texture2D

Last post 04-10-2008, 1:43 PM by MORT 8088. 4 replies.
Sort Posts: Previous Next
  •  04-09-2008, 4:49 PM

    A question about DrawableGameComponent and Texture2D

    I want to have two DrawableGameComponents one drawing the map and one drawing the players backpack.

    Is there a way I can load one set of sprites and have them both reference the same data or do I have to load two copys of Texture2D one in each Component?


    Xblog.org
  •  04-09-2008, 5:01 PM

    Re: A question about DrawableGameComponent and Texture2D

    If both components use the same ContentManager instance, they will both reference the same texture data. If they use different ContentManager instances, they will each load in a copy of the data. So just make sure to give both components a reference to the same ContentManager (passing it in during the constructor is how I usually do it) and you'll be all set.


    Nick Gravelyn -- Microsoft XNA MVP
    XNA Wiki | Zune Games
  •  04-10-2008, 1:18 PM

    Re: A question about DrawableGameComponent and Texture2D

    Ok, I've left it all day, but I now feel I have to question your *Answer*, but I do love the Tile Map Engine Videos...

    The question was, do I have to have two copys of the texture, one loaded into each component, or is there a way to get access to Texture2D objects in a central location?

    Edited to stop me looking so stupid.


    Xblog.org
  •  04-10-2008, 1:22 PM

    Re: A question about DrawableGameComponent and Texture2D

    Actually his answer was good... since the content reference you use in both components is the same one calling .Load<> on them will not actually create 2 copies of the texture it will reuse the data from the 1st one that loaded it. The content manager handles all of this for you automatically.

     



    The ZBuffer - News and information for XNA and Managed DirectX
  •  04-10-2008, 1:43 PM

    Re: A question about DrawableGameComponent and Texture2D

    Thanks, why did that explanation make sense, I think I may have got a bit confused.
    Xblog.org
View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback