- Double-click on
Game1.cs
in Solution Explorer to open it or bring it to the front if it is already open. - In the Class Declarations area of Game1 (right below
SpriteBatch spriteBatch;
), add:Texture2D playingPieces; Texture2D backgroundScreen; Texture2D titleScreen;
- Add code to load each of the
Texture2D
objects at the end ofLoadContent()
:
In order to load the textures from disk, you need an in-memory object to hold them. These are declared as instances of the Texture2D class.
A default XNA project sets up the Content
instance of the ContentManager class for you automatically. The Content
object's Load()
method is used to read .XNB
files from disk and into the Texture2D
instances declared earlier.
One thing to note here is that the Load()
method requires a type identifier, specified in angled brackets (< >), before the parameter list. Known in C# as a "Generic", many classes and methods support this kind of type specification to allow code to operate on a variety of data types. We will make more extensive use of Generics later when we need to store lists of objects in memory. The Load()
method is used not only for textures, but also for all other kinds of content (sounds, 3D models, fonts, etc.) as well. It is important to let the Load()
method know what kind of data you are reading so that it knows what kind of object to return.