GameContentManager

Description

Will load, store, and unload all assets in the game, including images and audio files. Will be a static member in the Window class so that it can be accessed by any class that needs to load/get assets. This will inherit from the standard ContentManager in the XNA framework. When loading in a new level any assets trying to be loaded with the Load method should be inbetween a StartLoading and EndLoading method calls. This will make sure that only new assets are actually loaded and that only assets that are no longer being used are disposed.

Relationships

  • Window : will be static member in the Window class so that any class that needs to get assets can do so.

Members

  • List<Asset> assets - a list of the Asset structs which have the name of an asset, the asset, and whether or not to keep it when changing levels
  • List<Asset> newAssets - all of the new assets that have been loaded
  • bool loadingNewAssets - if new assets are being loaded that needed to be check against the old ones

Methods

  • Load
    • if not loading new assets
      • first will check if the asset has already been loaded into the list. It will not load it if it has already
      • otherwise it will load the asset in using ReadAsset from the standard ContentManager which grabs assets that are in the Content folder of the game, and stores it in the assets List
    • if loading new assets
      • first it will check to see if the asset is in the assets list, if so it will grab the asset from assets and put it in newAssets List. If it does this, it will set the bool value in the struct to true so that it doesn't get disposed later
      • else, it will check to see if the asset is already in newAsset, if so it won't do anything.
      • else, it will load in the asset and add it to newAssets
  • Find
    • This will find an asset in based on the name passed in, and if its there will return it from the assets List
  • StartLoading
    • This method gets used when you start to load in a new level. sets loadingNewAssets to true
  • EndLoading
    • This method gets used when you are done loading a new level and need to dispose assets that aren't being used anymore.
    • First, it will go through all of the assets in the assets List. If an asset is supposed to be kept, based on the value in the keepAsset bool, that asset will only be removed. However if keepAsset is false then it will dispose of the assets before removing it from the list.
    • Second, it will transfer over all of the assets from the newAssets list over to the assets list, and also set loadingNewAssets to false
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License