Time for action – reading textures into memory
Double-click on
Game1.vb
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 Private WithEvents spriteBatch As SpriteBatch), add:
Private playingPieces As Texture2D Private background As Texture2D Private titleScreen As Texture2D
Add code to load each of the
Texture2D
objects at the end ofLoadContent()
:playingPieces = Content.Load(Of Texture2D)("Textures\Tile_Sheet") background = Content.Load(Of Texture2D)("Textures\Background") titleScreen = Content.Load(Of 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 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...