<< Chapter < Page | Chapter >> Page > |
Listing 6 begins by declaring two new instance variables of types Texture2D and Vector2 named myTexture and spritePosition respectively.
The variable named myTexture will be used in the LoadContent method of Listing 6 to store a reference to a Texture2D object created from the image file with the Asset Name of gorightarrow (see Figure 7 ). It will also be used later in the overridden Draw method where it is the sprite being drawn.
The variable named spritePosition will be used later in the overridden Draw method to specify the location to draw the sprite. I will have more to say about this variable later.
Here is some of what the documentation has to say about the Texture2D class.
You can view a diagram of a texture resource containing a single 3x5 texture with three mipmap levels here . You can read what Wikipedia has to say about mipmaps here . The image used in this program doesn't have any mipmaps.
The SurfaceFormat enumeration defines numeric values representing about 50 different types of surface formats such as Rgba32 , which is defined as
For example, the Properties Window in Figure 7 shows the image that I used for my program to have a Texture Format property value of Color . The definition of the SurfaceFormat enumeration for Color is
Note that this is similar to Rgba32 except that the position of the alpha byte relative to the other three bytes is different.
The code in the overridden LoadContent method of Listing 6 begins by instantiating a new SpriteBatch object and saving its reference in the reference variable named spriteBatch . (That variable is declared at the top of Listing 3 .)
According to the documentation , an object of the SpriteBatch class
The constructor for an object of the SpriteBatch class requires an incoming parameter that is a reference to the graphicsDevice of the current platform as type GraphicsDevice .
GraphicsDevice is the name of an XNA class. It is also the name of a property of the Game class that is inherited into the Game1 class. The parameter that is passed to the constructor for the SpriteBatch object in Listing 6 is the inherited property.
Notification Switch
Would you like to follow the 'Xna game studio' conversation and receive update notifications?