- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 274字
- 2021-08-20 15:50:37
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.
One thing to note here is that the Load()
method requires a type identifier, specified in the first set of parenthesis using the Of
notation, before the normal parameter list. Known in .Net programming 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, and so on) 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.
- Greenplum:從大數(shù)據(jù)戰(zhàn)略到實(shí)現(xiàn)
- Visual Studio 2015 Cookbook(Second Edition)
- Redis應(yīng)用實(shí)例
- 大數(shù)據(jù)可視化
- MySQL從入門到精通(第3版)
- 大數(shù)據(jù)導(dǎo)論
- INSTANT Cytoscape Complex Network Analysis How-to
- 淘寶、天貓電商數(shù)據(jù)分析與挖掘?qū)崙?zhàn)(第2版)
- SQL Server深入詳解
- 聯(lián)動(dòng)Oracle:設(shè)計(jì)思想、架構(gòu)實(shí)現(xiàn)與AWR報(bào)告
- Unity 2018 By Example(Second Edition)
- 數(shù)據(jù)挖掘算法實(shí)踐與案例詳解
- 工業(yè)大數(shù)據(jù)融合體系結(jié)構(gòu)與關(guān)鍵技術(shù)
- 工業(yè)大數(shù)據(jù)分析實(shí)踐
- 一本書讀懂區(qū)塊鏈(第2版)