XNA Creators Club Online
Page 1 of 1 (5 items)
Sort Posts: Previous Next

A question about DrawableGameComponent and Texture2D

Last post 04-10-2008 1:43 PM by MORT 8088. 4 replies.
  • 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 In reply to

    Re: A question about DrawableGameComponent and Texture2D

    Answer
    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
    Blog | XNA Wiki | FX-izer | EasyZip | Current Adventures | Next-Gen
  • 04-10-2008 1:18 PM In reply to

    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 In reply to

    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
    Please read the forum FAQs - Bug reporting
  • 04-10-2008 1:43 PM In reply to

    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
Page 1 of 1 (5 items) Previous Next