Time for action – reading textures into memory

  1. Double-click on Game1.cs in Solution Explorer to open it or bring it to the front if it is already open.
  2. In the Class Declarations area of Game1 (right below SpriteBatch spriteBatch;), add:
    Texture2D playingPieces;
    Texture2D backgroundScreen;
    Texture2D titleScreen;
  3. Add code to load each of the Texture2D objects at the end of LoadContent():
    playingPieces = Content.Load<Texture2D>(@"Textures\Tile_Sheet");
    backgroundScreen = Content.Load<Texture2D>(@"Textures\Background");
    titleScreen = Content.Load<Texture2D>(@"Textures\TitleScreen");
    

What just happened?

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 ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.