<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2903756005659412185</id><updated>2011-04-21T22:14:55.373-07:00</updated><category term='C# Primer'/><category term='2D Tutorials'/><category term='2D Tutorial Series'/><category term='Tutorials'/><category term='Getting Started With XNA'/><category term='Question and Answer'/><title type='text'>Christian Game Programming</title><subtitle type='html'>Welcome to my basic tutorial blog. This blog introduces XNA game programming using the C# language. I do hope that you learn from the text on this blog even though I am not such a good programmer myself. If you check this blog out, I thank you. 

Also, I want you to know that this site has been dedicated to my Lord and Savior. All I do is worthless unless it is done for Him. Thank you Lord.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-4589345107724288299</id><published>2008-01-09T08:52:00.000-08:00</published><updated>2008-01-09T09:08:35.945-08:00</updated><title type='text'>Creating a New Project</title><content type='html'>&lt;div align="left"&gt;Welcome to the first tutorial in the &lt;em&gt;2D Tutorial Series&lt;/em&gt;. In this tutorial series, I hope to introduce anyone who is new to C# and XNA game programming, to the programming world.&lt;br /&gt;&lt;br /&gt;In this first tutorial, we will create a new project, in which we will work in and create our small XNA applications in. It is assumed that you have already downloaded and installed both the &lt;em&gt;C# Express Edition&lt;/em&gt; and &lt;em&gt;XNA Game Studio Express 2.0&lt;/em&gt;. If you haven’t, then go to the &lt;em&gt;Getting Started&lt;/em&gt; tab on the right side of the page.&lt;br /&gt;&lt;br /&gt;Now, since everything is downloaded, we can begin. Open up the C# Express Edition which should be accessible from the Start menu. When you open up your project you should be greeted with the &lt;em&gt;Start Page&lt;/em&gt;. &lt;/div&gt;&lt;p align="left"&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/R4T9vh65A1I/AAAAAAAAALw/qML2nVZBuyg/s1600-h/StartPage.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5153522866619745106" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/R4T9vh65A1I/AAAAAAAAALw/qML2nVZBuyg/s400/StartPage.jpg" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p align="left"&gt;&lt;strong&gt;Figure 1.1: When you open the C# Express Edition, you will be greeted with the Start Page.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Now, we want to create a new project. This project is where we will create our applications in. When you create a new project, you can choose to either create a new, empty, blank project, or you can choose from a group of project templates. These templates do nothing special. All they do is start you out with the needed code and references for you to easily start creating your application. For us, we want to select a project template called the &lt;em&gt;Windows Game&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;From the &lt;strong&gt;File&lt;/strong&gt; tab, select &lt;strong&gt;New Project&lt;/strong&gt;. After this, a New Project dialog will show up. From this dialog, you can choose what type of project you would like to create. As said previously, we want to select the Windows Game project template. This should be the first template in the list. If you don’t see this option, make sure that on the left side of the dialog, you have &lt;em&gt;XNA Game Studio 2.0&lt;/em&gt; selected.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/R4T9wB65A4I/AAAAAAAAAMI/XBUpzb7v5e0/s1600-h/FileNewProject.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5153522875209679746" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/R4T9wB65A4I/AAAAAAAAAMI/XBUpzb7v5e0/s400/FileNewProject.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1.2: Create a new project by clicking File / New Project.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Click on the &lt;strong&gt;Windows Game&lt;/strong&gt; template. At the bottom of the page, you will see a few options for naming your project. I named it, &lt;em&gt;TutorialProject&lt;/em&gt;. However, if you dislike this name, feel free to choose something different. The save location is made by default, and is probably where you want to save it. This path saves the project into the Projects directory, where you can easily access it when you open a file in XNA GSE (Game Studio Express). The final textbox is where you can specify the solution name. It is possible to have multiple projects in a single solution, so you may want to name the solution different from an individual project. For our purposes, leave the name as it is. Also, make sure that the &lt;em&gt;Create directory for solution checkbox&lt;/em&gt; is checked because we are creating a new solution and not adding a project to an existing solution. Finally, press &lt;strong&gt;OK&lt;/strong&gt;, to create the project.&lt;br /&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/R4T9vx65A2I/AAAAAAAAAL4/HJTDOgHdVgM/s1600-h/NewTutorialProject.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5153522870914712418" style="CURSOR: hand" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/R4T9vx65A2I/AAAAAAAAAL4/HJTDOgHdVgM/s400/NewTutorialProject.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1.3: When you have completed the steps above, your project profile should look similar to this.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;After a few moments, you will be greeted with the &lt;em&gt;Game1.cs&lt;/em&gt; class file, which has been created for you by default. The default code may look confusing, but after a while you will get the hang of what happens. For now though, let’s see what the default code does. Build the project by clicking the green &lt;em&gt;Start Debugging&lt;/em&gt; arrow at the top, middle of the screen (or by pressing &lt;em&gt;F5&lt;/em&gt;). Your project will build and you will see an already created window for you, with a nice cornflower blue color as the background.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/R4T9vx65A3I/AAAAAAAAAMA/H8xkEFy0uSQ/s1600-h/BlueScreen.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5153522870914712434" style="CURSOR: hand" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/R4T9vx65A3I/AAAAAAAAAMA/H8xkEFy0uSQ/s400/BlueScreen.jpg" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Figure 1.4: When you build the project by clicking the green arrow or pressing F5, you will see this screen created for you by default.&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;It’s nice to know that you don’t have to go through all the work of creating a window by hand and that you can start seeing results very quickly. In this tutorial, you learned how to create a new project. You didn’t code anything, but that is coming in the next tutorial.&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Be a hero: don’t conform; be selfless; make a difference. &lt;/em&gt;&lt;/strong&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-4589345107724288299?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/4589345107724288299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=4589345107724288299' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4589345107724288299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4589345107724288299'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2008/01/creating-new-project.html' title='Creating a New Project'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_kLtxSdyLIgE/R4T9vh65A1I/AAAAAAAAALw/qML2nVZBuyg/s72-c/StartPage.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-1917156451690785817</id><published>2008-01-09T08:43:00.000-08:00</published><updated>2008-01-09T09:10:45.727-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorial Series'/><title type='text'>2D Tutorial Series</title><content type='html'>Welcome to the 2D Tutorial Series. In this series, we explore XNA and how we can use it for programing 2D applications. 3D graphics is a whole new topic, so we stick to 2D in this series.&lt;br /&gt;&lt;br /&gt;This series is written using C# and XNA Game Studio 2.0. No knowledge of either is needed to begin, as this tutorial series is written for total beginners.&lt;br /&gt;&lt;br /&gt;If you find any errors in any of the tutorials, or if any of the tutorials were confusing, please let me know with a comment. Thanks all.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2008/01/creating-new-project.html"&gt;Tutorial 1: Creating a New Project&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-1917156451690785817?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/1917156451690785817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=1917156451690785817' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1917156451690785817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1917156451690785817'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2008/01/2d-tutorial-series.html' title='2D Tutorial Series'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-1044728339965956879</id><published>2007-12-19T15:06:00.000-08:00</published><updated>2007-12-20T14:46:20.241-08:00</updated><title type='text'>Lighting Demo</title><content type='html'>&lt;span style="font-family:lucida bright;"&gt;&lt;h1&gt;Creating a Simple Shader&lt;/h1&gt;&lt;p&gt;First, before anything, we need to create the shader that will be used to render our pixels onto the screen. For starters, all the shader will do is transform the geometry into correct world, view, and projection space, and then output all pixels white. Later, however, we will add cool lighting effects for all kinds of materials.&lt;/p&gt;&lt;p&gt;Open up an empty &lt;b&gt;Notepad&lt;/b&gt; document. Click the &lt;b&gt;File&lt;/b&gt; menu tab and then click &lt;b&gt;Save As&lt;/b&gt;. Name the document &lt;i&gt;Transform.fx&lt;/i&gt; (you will need to switch the &lt;b&gt;Files of Type&lt;/b&gt; box to &lt;b&gt;All Files&lt;/b&gt;). Finally, place the document somewhere easily accessed and click &lt;b&gt;Save&lt;/b&gt;.&lt;/p&gt;&lt;h3&gt;Effect Parameters&lt;/h3&gt;&lt;p&gt;The first things we want to add to our shader are effect parameters. These types of variables are used to allow access for the XNA app so that we can manipulate how the shader renders the geometry. At the moment, we only need one parameter that holds the world, view, and projection matrices. We need this parameter to transform all the geometry (vertices) from their local space coordinates to the correct world, view, and projection space.&lt;/p&gt;&lt;p&gt;At the top of the file, add this code:&lt;/p&gt;&lt;p&gt;&lt;pre&gt;uniform extern float4x xWorldViewProjection;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;uniform extern&lt;/span&gt; just means that this variable is like a parameter that can be accessed by the XNA app. &lt;span style="font-family:courier new;"&gt;float4x4&lt;/span&gt; is a type that defines a 4x4 matrix variable (which means the same as &lt;span style="font-family:courier new;"&gt;Matrix&lt;/span&gt; in XNA). &lt;p&gt;&lt;/p&gt;&lt;h3&gt;The VertexInput Structure&lt;/h3&gt;&lt;p&gt;The next step we need to take is to create a structure that defines what type of data the vertex shader takes in from the XNA app.&lt;/p&gt;&lt;p&gt;All the data that we want to take in for now is vertex position data (we do not need color data because we will just output all pixels white). With this in mind, we will have a very simple &lt;span style="font-family:courier new;"&gt;VertexInput&lt;/span&gt; structure. Underneath the effect parameter, create the &lt;span style="font-family:courier new;"&gt;VertexInput&lt;/span&gt;:&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;&lt;pre&gt;// Vertex input&lt;br /&gt;struct VertexInput&lt;br /&gt;{&lt;br /&gt;    float3 pos : POSITION;&lt;br /&gt;};&lt;/pre&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;As you may have guessed, &lt;span style="font-family:courier new;"&gt;float3&lt;/span&gt; is a keyword that creates a variable similar to an XNA &lt;span style="font-family:courier new;"&gt;Vector3&lt;/span&gt;. Also, we have the &lt;span style="font-family:courier new;"&gt;: POSITION0&lt;/span&gt;. This is called a variable &lt;i&gt;semantic&lt;/i&gt;. The reason for using these is so that the shader knows how to map data incoming from the XNA app to their corresponding variables in the shader (we don’t want the shader to confuse vertex normal data with vertex position data).&lt;/p&gt;&lt;h3&gt;The VertexOutput Structure&lt;/h3&gt;&lt;p&gt;After the &lt;span style="font-family:courier new;"&gt;VertexInput&lt;/span&gt; structure, we create the &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt;. The &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt; structure defines what type of data will be given to the pixel shader. The pixel shader is called after the vertex shader, but does processing on every pixel instead of every vertex. Some operations only need to be done per-vertex instead of per-pixel which can increase performance (generally there are many more pixels than vertices). These operations are completed in the vertex shader. When the pixel shader comes into play, it takes in data from the vertex shader to use for processing the pixels. We declare this data structure in a &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt; structure.&lt;/p&gt;&lt;p&gt;Below the &lt;span style="font-family:courier new;"&gt;VertexInput&lt;/span&gt; structure, we can now create the &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt;:&lt;/p&gt;&lt;p&gt;&lt;pre&gt;// Vertex output&lt;br /&gt;struct VertexOutput&lt;br /&gt;{&lt;br /&gt;    float4 pos : POSITION;&lt;br /&gt;};&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;All we need to output to the pixel shader is the position of the vertex once it has been transformed into correct space. The position has also now been changed to a &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt;, which could be looked at like an XNA &lt;span style="font-family:courier new;"&gt;Vector4&lt;/span&gt;. The reason for this is so that we can multiply this position with matrices. Also, you may be wondering why we don’t output any color. Usually, we would output a vertex color, but, because our simple pixel shader will only output white color data for every pixel, it would be a waste to store color output for each vertex.&lt;/p&gt;&lt;h3&gt;The Vertex Shader&lt;/h3&gt;&lt;p&gt;Now we can create the &lt;i&gt;vertex shader&lt;/i&gt;. The vertex shader is called first and does operations on the vertices, also known as the geometry, of the mesh to be drawn.&lt;/p&gt;&lt;p&gt;Below the &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt; structure, add the vertex shader:&lt;/p&gt;&lt;p&gt;&lt;pre&gt;// Vertex shader&lt;br /&gt;VertexOutput VS_Transform(VertexInput input)&lt;br /&gt;{&lt;br /&gt;    // Zero out our output.&lt;br /&gt;    VertexOutput output = (VertexOutput)0;&lt;br /&gt;&lt;br /&gt;    // Transform the position of the vertex into correct world,&lt;br /&gt;    // view, and projection space.&lt;br /&gt;    output.pos = mul(float4(input.Pos, 1.0f), xWorldViewProjection);&lt;br /&gt;&lt;br /&gt;    // Done--return the output.&lt;br /&gt;    return out;&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is a very, very simple vertex shader. The first line in the vertex shader zeroes out the output that the vertex shader will return. The next line transforms the vertex into correct world, view, and projection space. We use the HLSL intrinsic &lt;span style="font-family:courier new;"&gt;mul&lt;/span&gt; function to multiply a &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt; and a &lt;span style="font-family:courier new;"&gt;float4x4&lt;/span&gt;. However, the in-position of the vertex is a &lt;span style="font-family:courier new;"&gt;float3&lt;/span&gt;, which means we need to convert the &lt;span style="font-family:courier new;"&gt;float3&lt;/span&gt; to a &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt;. We do this by creating a &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt; and passing the in-position and 1 as parameters to the constructor (we pass in 1 as the w-component because the position is a location vector (point). If the vector were a normal or other vector that did not have a position on the screen, but only a direction, then we would specify 0 for the w-component). Also, you will notice that we multiply the position, now in homogeneous (4-component) coordinates, by the world, view, and projection matrices. These matrices can change for each object in the application, thus explains why we make this variable an effect parameter.&lt;/p&gt;&lt;p&gt;Finally, we are finished manipulating the output and can give it to the pixel shader. Note though, that the pixel shader will not actually use the output’s position. Even in advanced shaders, the pixel shader uses color data and texture data. The output’s position is used by the graphics card to place the vertices in correct world, view, and projection space.&lt;/p&gt;&lt;h3&gt;The Pixel Shader&lt;/h3&gt;&lt;p&gt;The &lt;i&gt;pixel shader&lt;/i&gt; is called after the vertex shader and does processing on all of the pixels in the geometry, finally outputting a color for the pixel. Below the vertex shader, create the pixel shader:&lt;/p&gt;&lt;p&gt;&lt;pre&gt;// Pixel shader&lt;br /&gt;float4 PS_Transform() : COLOR&lt;br /&gt;{&lt;br /&gt;    // Output white for each pixel.&lt;br /&gt;    return float4(1.0f, 1.0f, 1.0f, 1.0f);&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Usually, lighting calculations and other processing for cool effects would be done here, but for now, all we do is output the color white. Notice, however, that we didn’t take in a &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt; parameter to the pixel shader. Usually we would but because we don’t need any of the information in the &lt;span style="font-family:courier new;"&gt;VertexOutput&lt;/span&gt; structure, we don’t need to bother with parameters. Finally, a unique detail of the pixel shader is that it represents a color. The pixel shader has a return value of a &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt;, which is like a color (r, g, b, a) and also has a &lt;span style="font-family:courier new;"&gt;: COLOR&lt;/span&gt; semantic attached to it. Also, note that &lt;span style="font-family:courier new;"&gt;float4&lt;/span&gt;, which can be interpreted as an XNA &lt;span style="font-family:courier new;"&gt;Vector4&lt;/span&gt;, can also represent an XNA &lt;span style="font-family:courier new;"&gt;Color&lt;/span&gt;, which has four components as well.&lt;/p&gt;&lt;h3&gt;The Technique&lt;/h3&gt;&lt;p&gt;We are now 90 percent done with our simple shader. All we have left to do is add the &lt;i&gt;technique&lt;/i&gt;, which respectively calls the vertex and pixels shaders associated with that technique. It is possible to have many different techniques, inputs, outputs, vertex shaders, pixel shaders, and effect parameters in one shader file. You could use this ability to call different vertex and pixel shaders depending on what kind of shader model the user’s computer could support. In the XNA app you would determine which level the computer can support and then call the corresponding technique (e.g. WaterTech1, WaterTech2) which would call the correct vertex and pixel shaders for your computer. This allows for extra flexibility because the user could use the same application without having to get a better graphics card. For us, however, we will just use shader model 2.0.&lt;/p&gt;&lt;p&gt;Below everything you have so far, create the technique for our transform shader:&lt;/p&gt;&lt;p&gt;&lt;pre&gt;// Transform&lt;br /&gt;technique Transform&lt;br /&gt;{&lt;br /&gt;    pass P0&lt;br /&gt;    {&lt;br /&gt;        // Compile the vertex and pixel shaders for this&lt;br /&gt;        // shader using vertex and pixel versions 2.0.&lt;br /&gt;        vertexShader = compile vs_2_0 VS_Transform();&lt;br /&gt;        pixelShader = compile ps_2_0 PS_Transform();&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;First, we declare the technique and the name of the technique. Next, we declare a &lt;i&gt;pass&lt;/i&gt;. A pass is a loop inside the technique that calls the associated vertex and pixel shaders. A technique may want to contain more than one pass for special effects so in the XNA app you need to loop through the passes in the currently set technique. Note however that using two passes doubles the processing time for the geometry, and using three passes makes it even worse. If you don’t need to use multiple passes, it would probably be best not to.&lt;/p&gt;&lt;p&gt;Inside the pass, we set the vertex and pixel shaders, respectively, to the vertex and pixel shaders we made previously. Also, we compile our vertex and pixel shaders using vertex and pixel versions 2.0.&lt;/p&gt;&lt;p&gt;We are now done creating the shader, which can be used in any application. We learned how to create effect parameters, vertex input and output structures, vertex shaders, pixel shaders, and techniques. Also, hopefully you learned a bit about the structure of HLSL and how to do some basic coding with it. In the next parts, we will learn how to apply shaders to geometry in the XNA application.&lt;/p&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-1044728339965956879?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/1044728339965956879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=1044728339965956879' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1044728339965956879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1044728339965956879'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/12/creating-simple-shader-first-before.html' title='Lighting Demo'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-5006173723686674206</id><published>2007-11-22T19:50:00.000-08:00</published><updated>2007-11-22T19:54:01.796-08:00</updated><title type='text'>What are all the possible texture file types that can be used?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; What are all the possible texture file types that can be used?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Answer: &lt;/strong&gt;The texture file types that can be loaded using the Content Pipeline are: Bmp, Dds, Dib, Hdr, Jpg, Pfm, Ppm, and Tga.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-5006173723686674206?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/5006173723686674206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=5006173723686674206' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5006173723686674206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5006173723686674206'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/what-are-all-possible-texture-file.html' title='What are all the possible texture file types that can be used?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-7188871586907597774</id><published>2007-11-18T18:48:00.001-08:00</published><updated>2007-11-18T18:49:06.131-08:00</updated><title type='text'>How do I build a rectangle around an object?</title><content type='html'>&lt;strong&gt;Question:&lt;/strong&gt; How do I build a rectangle around an object?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer:&lt;/strong&gt; By using the Rectangle class, an invisible box can be created and used for collision checking, or for virtually any other purpose.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Rectangle rect = new Rectangle((int)objectPosition.X, (int) objectPosition.Y, objectTexture.Width, objectTexture.Height);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above code shows a common way a Rectangle is created to wrap an object. The Rectangle constructor takes an X and Y coordinate to be the base corner of the rectangle, and then a width and height for the dimensions of the rectangle. In the code above, we retrieved the X and Y coordinates from a Vector2, and we retrieved the width and height from a Texture2D. This is just one way of creating a Rectangle though, and there are many other possibilities also.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-7188871586907597774?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/7188871586907597774/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=7188871586907597774' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7188871586907597774'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7188871586907597774'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-do-i-build-rectangle-around-object.html' title='How do I build a rectangle around an object?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-7195197245875509974</id><published>2007-11-18T18:27:00.000-08:00</published><updated>2007-11-18T18:34:22.064-08:00</updated><title type='text'>How do I check if two rectangles are overlapping?</title><content type='html'>&lt;span &gt;&lt;strong&gt;Question:&lt;/strong&gt; How do I check if two rectangles are overlapping?&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;strong&gt;Answer:&lt;/strong&gt; If you have two Rectangles and all you want to do is check if they are overlapping eachother or not, you can easily make use of the Intersects method.&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;/span&gt;&lt;br /&gt;&lt;span &gt;In code, let's say you have two Rectangles called rect1 and rect2. To check if they overlap, you could have an if-statement like this:&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (rect1.Intersects(rect2))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Code&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;strong&gt;Note:&lt;/strong&gt; It doesn't matter which Rectangle you call Intersects fom.&lt;/span&gt;&lt;br /&gt;&lt;span &gt;&lt;/span&gt;&lt;br /&gt;&lt;span &gt;In the code above, we check if any part of rect1 intersects any part of rect2. If rect1 and rect do overlap, Intersects will return true and then you can continue from there.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-7195197245875509974?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/7195197245875509974/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=7195197245875509974' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7195197245875509974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7195197245875509974'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-do-i-check-if-two-rectangles-are.html' title='How do I check if two rectangles are overlapping?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-589107699891119468</id><published>2007-11-17T16:26:00.000-08:00</published><updated>2007-11-18T13:18:18.474-08:00</updated><title type='text'>Any Requests?</title><content type='html'>Hello,&lt;br /&gt;&lt;br /&gt;It would be nice to see what the community wants to know at the moment. If you have a specific request, please post a comment.&lt;br /&gt;&lt;br /&gt;Thanks&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-589107699891119468?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/589107699891119468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=589107699891119468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/589107699891119468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/589107699891119468'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/any-requests.html' title='Any Requests?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-3132430620285102304</id><published>2007-11-17T16:15:00.000-08:00</published><updated>2007-11-17T16:22:30.216-08:00</updated><title type='text'>How can I check if a key is down or not?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; How can I check if a key is down or not? &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Answer: &lt;/strong&gt;To check the state of a key on the keyboard, can call the IsKeyDown or IsKeyUp methods of a KeyboardState variable.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Inside of the Update method, create a KeyboardState and set it to the current state of the Keyboard.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;KeyboardState keyboard = Keyboard.GetState();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;After that, you can add the if-statement to check the value of a given key:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;if (keyboard.IsKeyDown(Keys.Space))&lt;br /&gt;{&lt;br /&gt;//Code&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;By using the Keys enum type, we can check against any key on the keyboard.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-3132430620285102304?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/3132430620285102304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=3132430620285102304' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3132430620285102304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3132430620285102304'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-can-i-see-if-key-is-down-or-not.html' title='How can I check if a key is down or not?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-4408913770184355153</id><published>2007-11-17T14:33:00.000-08:00</published><updated>2007-11-17T14:49:41.210-08:00</updated><title type='text'>How can I check to see if a controller button is down?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; How can I check to see if a controller button is down?&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;Answer: &lt;/strong&gt;The key to tracking input from the Xbox 360 controller is the GamePadState class. To track if a controller button is down, we want to check the ButtonState of the button in a GamePadState. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;First, inside of the Update method, create a GamePadState variable:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;GamePadState gamePad = GamePad.GetState(PlayerIndex.One);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;After creating the GamePadState, we then initialize it with the current value of player one's game pad. Since this code is processed every Update method, the value that our GamePadState contains is always valid.&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Now, we can check to the value of the controller. In the Update method, you would add something like this to check if a button is pressed:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;if (gamePad.Buttons.A == ButtonState.Pressed)&lt;br /&gt;{&lt;br /&gt;//Code&lt;br /&gt;}&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Trebuchet MS;"&gt;In the above if-statement, we ask if the A button is pressed. If it is, then the code inside the if-statement will be processed. You can also check if the button is released by checking against ButtonState.Released.&lt;/span&gt; &lt;ol&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Courier New;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-4408913770184355153?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/4408913770184355153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=4408913770184355153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4408913770184355153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4408913770184355153'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-can-i-check-to-see-if-xbox-360.html' title='How can I check to see if a controller button is down?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-8527251845496452236</id><published>2007-11-17T12:07:00.000-08:00</published><updated>2007-11-17T12:24:50.057-08:00</updated><title type='text'>How do I scale the size of a sprite?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question: &lt;/strong&gt;How do I scale the size of a sprite?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Scaling the size of a sprite when drawn consists of only one step: modifying the scale parameter of a spriteBatch.Draw call.&lt;br /&gt;&lt;br /&gt;After creating a SpriteBatch, between the Begin and End calls, you will want to call spriteBatch.Draw(...); There are seven different overloads of Draw but only two of them take scale parameters. These are overloads 6 and 7.&lt;br /&gt;&lt;br /&gt;You would call the Draw method with overload 6 as follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.Draw(texture, position, sourceRect, color, rotation,&lt;br /&gt;origin, &lt;strong&gt;scale&lt;/strong&gt;, spriteEffects, depth);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The seventh parameter is the scale. This parameter is a float. The default value is 1. Note that if you specify 0, the sprite will dissapear because all its dimensions will be multiplied by 0 which will result in 0.&lt;br /&gt;&lt;br /&gt;You would call the Draw method with overload 7 as follows:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.Draw(texture, position, sourceRect, color, rotation, origin, &lt;strong&gt;scaleVector&lt;/strong&gt;, spriteEffects, depth);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Again, the seventh parameter is the scale parameter. This parameter is different from overload 6 in that it is a Vector2 instead of a float. The reason for this is so that the user can scale the width of the texture differently from the height.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; You could also scale a texture by using the destination rectangle, but that will not be covered in this post.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-8527251845496452236?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/8527251845496452236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=8527251845496452236' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8527251845496452236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8527251845496452236'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/question-how-do-i-scale-size-of-sprite.html' title='How do I scale the size of a sprite?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-67948222637067161</id><published>2007-11-16T17:13:00.001-08:00</published><updated>2007-11-16T17:16:43.191-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Getting Started With XNA'/><title type='text'>Getting Started with XNA</title><content type='html'>Getting started with XNA is very simple and easy. Here are a few posts to help out with this process.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/08/what-is-xna.html"&gt;A Quick Article on What XNA Is&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/08/xna-and-c-download-instructions.html"&gt;The XNA and C# Express Edition Download Instructions&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-67948222637067161?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/67948222637067161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=67948222637067161' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/67948222637067161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/67948222637067161'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/getting-started-with-xna.html' title='Getting Started with XNA'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-576952365910810711</id><published>2007-11-15T17:06:00.000-08:00</published><updated>2007-11-15T17:09:28.518-08:00</updated><title type='text'>How to Print Simple Text onto the Screen</title><content type='html'>&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;Most games need to be able to render text on the screen. Since many people would like to know how to do this, I’ve decided to write a small tutorial on this subject.&lt;br /&gt;&lt;br /&gt;Text in itself is rendered onto the screen in the same way as a texture; through a bitmap image. On this image, every letter and symbol has its own small area. Before XNA 1.0 came out, I saw text being rendered through someone using their own system where a string is dissected and then each letter is drawn separately. Fortunately for us though, XNA 1.0 gives us the SpriteFont. This name refers both to an XML file and a C# class.&lt;br /&gt;&lt;br /&gt;As said before, to render text follows almost the same concepts as rendering textures. The steps in the process are few and simple: &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;Create a SpriteFont XML file and specify the needed properties.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Load the SpriteFont file using the Content Pipeline, into a SpriteFont class.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Render text using the specified SpriteFont and a shader (we use the SpriteBatch).&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;From these steps it is very easy to recognize the similarity between rendering textures and rendering text.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Creating the SpriteFont&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;So the first step to implementing a certain font is to create that font. This can be accomplished using the SpriteFont XML file. Inside of the Solution Explorer, &lt;strong&gt;right click&lt;/strong&gt; on your project and click &lt;strong&gt;Add / New Item&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RzpgEPzVo9I/AAAAAAAAAIU/VYnowdtU88Y/s1600-h/AddNewItemSE.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132520351419704274" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RzpgEPzVo9I/AAAAAAAAAIU/VYnowdtU88Y/s400/AddNewItemSE.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; Right Click on your project name and click Add / New Item.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; A default Windows Game template is used with the namespace of WindowsGame1. It is not in the scope of this lesson to explain about project templates though.&lt;br /&gt;&lt;br /&gt;You should now be taken to a page where you can choose what you want to create. We want to create a SpriteFont. Click on that template and name the SpriteFont, “Verdana”.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RzpgEPzVo-I/AAAAAAAAAIc/DYQ5pdnpzWA/s1600-h/AddSpriteFontVerdana.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132520351419704290" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RzpgEPzVo-I/AAAAAAAAAIc/DYQ5pdnpzWA/s400/AddSpriteFontVerdana.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 2:&lt;/strong&gt; Create a SpriteFont named “Verdana”.&lt;br /&gt;&lt;br /&gt;After clicking &lt;strong&gt;Add&lt;/strong&gt;, in your Solution Explorer you will see the Verdana.spritefont file in your list. This file is already opened. If you take a quick look around the file you will notice several different XML tags specifying the different properties of the font. These properties are as follows: &lt;ul&gt;&lt;li&gt;&lt;strong&gt;FontName:&lt;/strong&gt; This property changes the font family of the font (i.e. Times New Roman, Verdana, etc.). &lt;/li&gt;&lt;li&gt;&lt;strong&gt;Size:&lt;/strong&gt; This property changes the size of the font.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Spacing:&lt;/strong&gt; This property changes the amount of spacing in between the characters of the text. Usually, you can leave this as the default value of two.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Style:&lt;/strong&gt; This property changes the appearance of your text. You can enter “Regular” for no changes; “Bold” for bolded text; “Italic” for italicized text; or finally, “Bold, Italic” for both bolded and italicized text. Unfortunately, there is not ability for underlined text.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;For our simple purposes, we will leave the font properties as they are.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; If understanding the XML is confusing, do not worry. That is not necessary as long as you know what text you change. For all tags there is a common structure: [name]text[/endname] &lt;name&gt;Where you want to place the code is where the “text” would be; in between the name and endname tags.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Code Note: &lt;/strong&gt;For the rest of the tutorial, open and close brackets will be used to replace open and close tags. I cannot use tags in the text due to the HTML problems.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Using the Content Pipeline to Create a SpriteFont Class&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Now that we have our SpriteFont file created, we can load it into a SpriteFont class. This class will then be used to draw a specified string along with the help of the SpriteBatch class.&lt;br /&gt;The first step is to create a variable for the SpriteFont. At the top of the class where the GraphicsDeviceManager and ContentManager are created, add this code:&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;//The SpriteFont to hold the Verdana XML font.&lt;br /&gt;SpriteFont verdanaFont;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Next, we can initialize this variable. Similar to a Texture2D, instead of calling the constructor of the SpriteFont class (which is virtually useless) we instead directly load it with an outside file using content.Load(). We want to place this code into the LoadGraphicsContent method (so that it can be re-loaded when necessary), specifically inside of the if (loadAllContent) statement:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Init the SpriteFont with a real SpriteFont file&lt;br /&gt;//from the Solution Explorer.&lt;br /&gt;verdanaFont = content.Load[Texture2D]&lt;spritefont&gt;("Verdana");&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Code Note: &lt;/strong&gt;Switch the two forward and backward slashes for tags. I couldn't use tags in this post because of the HTML. This code practice will be used for the rest of the tutorial.&lt;/p&gt;&lt;p&gt;This code first calls the Load method of the ContentManager variable content and tells it to load a SpriteFont. Then, we pass in the name of the SpriteFont XML file. Notice that we remove the file extension (i.e. .spriteFont).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; The reason why we load the SpriteFont inside of the LoadGraphicsContent method is not to be explained in this lesson. For now you don’t really need to know anyway.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Rendering Text onto the Screen Using the SpriteBatch&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Finally, we have come to the part where we can render text onto the screen. As said earlier, a font is exactly the same in that it is a bitmap image that needs to be rendered. The SpriteBatch class, which is commonly used to render textures, can also be used along with its DrawString method to render text. Note that, the SpriteBatch actually draws the text. All the SpriteFont does is hold the value of what the text will look like.&lt;br /&gt;&lt;br /&gt;Since we first need a SpriteBatch to begin drawing, add this code to the top of your class along with the other variable declarations. This code creates a SpriteBatch variable.&lt;br /&gt;&lt;summary&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//The SpriteBatch used to draw the text.&lt;br /&gt;&lt;/summary&gt;SpriteBatch spriteBatch;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now we want to initialize this variable. Inside of the Initialize method, place this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Initialize the SpriteBatch.&lt;br /&gt;spriteBatch = new SpriteBatch(graphics.GraphicsDevice);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The SpriteBatch constructor needs a GraphicsDevice class in order to be initialized. The GraphicsDeviceManager graphics has a GraphicsDevice in it, so we just use that.&lt;br /&gt;&lt;br /&gt;Finally, we can draw the text. Using the SpriteBatch class and the SpriteFont class, we can render any string that we want. Inside of the Draw method, after the graphics.GraphicsDevice.Clear(Color.CornflowerBlue); line, add this code.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;/*Start the SpriteBatch. This call is required to set different &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;options. For us, we don't need any special modes so we call the &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;zero-parameter method.*/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.Begin(); &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;/*Draw the font. We pass in the SpriteFont to use, the string to draw, the position, and the color of the text.*/&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.DrawString(verdanaFont, "Look at me!!", new&lt;br /&gt;Vector2(100, 100), Color.Black); &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;/*Finally, end the SpriteBatch. For better processing results, all things to draw are placed in a list. When we call End, we draw all these things at once. Also, we return the different changed parameters back to their default values.*/&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;p&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.End();&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code may seem confusing, but it can be easily divided into three simple parts.&lt;br /&gt;&lt;br /&gt;First, we start the SpriteBatch. This is needed so that we can set different render-states for the device such as alpha-blending (transparency), or the way you want sprites to be sorted.&lt;br /&gt;&lt;br /&gt;Then, you draw the SpriteBatch. This is the most important part of the code. In this call, we pass in several different parameters. First, we pass in the SpriteFont to be used. For us we passed in our Verdana font. Next, there is the actual string to draw. This can be anything you want. After this we pass in the position. The position is stored as a Vector2. We pass in 100, 100, which is just a little off of the top-left corner of the screen. Note that the top, left corner of the first letter of the string will be drawn at 100, 100. To change this you need to change the origin of where the text is drawn. Finally, we have the color of the text which mostly explains its purpose by its name.&lt;br /&gt;&lt;br /&gt;The last part of the code is the call to end the SpriteBatch. As mentioned in the comments, it would be very inefficient to render each sprite whenever a Draw call was made. For this reason, all sprites to be drawn are put into a list. When the End method is called, all the sprites in the list are drawn at once. Also, once all the sprites are drawn, the different render-states for the device are reset back to their original values.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;The Final Results&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Finally, we can see the results of our work. If you run the project (F5), you should see something very similar to this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RzpgEvzVo_I/AAAAAAAAAIk/AcVV7ACj_HY/s1600-h/LookAtMeTextResult.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132520360009638898" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RzpgEvzVo_I/AAAAAAAAAIk/AcVV7ACj_HY/s400/LookAtMeTextResult.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt; The results of our efforts. Simple text printed onto the screen.&lt;br /&gt;&lt;br /&gt;Hopefully, now you will see, “Look at me!!” written onto the screen. If you do not see these results or if you are confused or found an error, please post a comment so that I can fix it. I do hope this helped you with in your programming quest.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-576952365910810711?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/576952365910810711/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=576952365910810711' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/576952365910810711'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/576952365910810711'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-to-print-simple-text-onto-screen.html' title='How to Print Simple Text onto the Screen'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_kLtxSdyLIgE/RzpgEPzVo9I/AAAAAAAAAIU/VYnowdtU88Y/s72-c/AddNewItemSE.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6218175184784256745</id><published>2007-11-15T17:04:00.002-08:00</published><updated>2007-11-15T17:05:32.336-08:00</updated><title type='text'>How to Render a Sprite Using the SpriteBatch</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;One of the most common requests for a beginner programmer would probably be how to render a 2D image onto the screen. This process is not actually very complicated at all. Using the SpriteBatch class given to us you can render 2D texture images in no time.&lt;br /&gt;&lt;br /&gt;To render a sprite (a 2D texture) there are three main steps that need to be followed. These steps are as follows: &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Add an image to your project so that it can be accessed in your code.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Create a Texture2D variable in your project and load the texture image into that variable using the Content Pipeline.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Draw the texture onto the screen with certain parameters that you would like to be applied to the texture.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Adding an Image to Your Project&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;First, before you can draw the texture, you need to be able to access the texture you want to draw. Through a system called the Content Pipeline, you can load different content files into your project and then access them using a ContentManager. Though this process is important, we first need to load an image into our project.&lt;br /&gt;&lt;br /&gt;To load an image, you need to first navigate to your Solution Explorer (View / Solution Explorer). After this, &lt;strong&gt;right click&lt;/strong&gt; on the name of your project and select &lt;strong&gt;Add / Existing Item&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RzugUfcdJnI/AAAAAAAAAI8/eqveCMh6x4w/s1600-h/AddExistingItemSE.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132872474217490034" style="CURSOR: hand" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RzugUfcdJnI/AAAAAAAAAI8/eqveCMh6x4w/s400/AddExistingItemSE.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; Right click on the name of your project and select Add / Existing Item&lt;br /&gt;&lt;br /&gt;You should now be taken to a page where you can browse through your computer files. What you want to do is browse to where a simple texture is located. Once you have located where the file should be, in the Files of Type drop-down box, switch to Content Pipeline Files. This option shows all files that XNA will allow to be added to your project. Most likely, your image is of file type TGA, PNG, BMP, JPG, or DDS, all of which can be added into your project. Once your file is select, click Add. The file now should be added to your Solution Explorer where you can see it:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RzugT_cdJlI/AAAAAAAAAIs/ROWQgBB2Trk/s1600-h/StoneTextureInSolutionExplorer.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132872465627555410" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RzugT_cdJlI/AAAAAAAAAIs/ROWQgBB2Trk/s400/StoneTextureInSolutionExplorer.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 2:&lt;/strong&gt; You can now see the texture file inside of your Solution Explorer. My texture was a JPG file called StoneTexture.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Creating a Variable to Hold the Texture&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;After loading an image into our project, we can now create a variable to contain that image data. This variable will then be used to draw the image onto the screen.&lt;br /&gt;&lt;br /&gt;First, because our texture is a 2D image, we want to create a variable of type Texture2D. Create this variable at the top of the class near the GraphicsDeviceManager and ContentManager variables.&lt;br /&gt;&lt;summary&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//The texture variable that will hold our image data.&lt;br /&gt;&lt;/summary&gt;Texture2D texture;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Next, we need to initialize this variable. With most variables, you call the constructor of the class to create it. Unlike these classes, all content-related variables are created by directly loading them with a file. For our case, this will be the texture loaded into our project. Because of graphics device related issues which do not need to be explained in this lesson, put this code inside of the if (loadAllContent) statement of the LoadGraphicsContent method. This code initializes our Texture2D:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;/*Use the ContentManager content variable to initialize&lt;br /&gt;the Texture2D with a real texture.*/&lt;br /&gt;texture = content.Load[Texture2D]&lt;texture2d&gt;("StoneTexture");&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Code Note: &lt;/strong&gt;The brackets in the above code should actually be tags. I needed to use brackets because the HTML would not allow tags.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;This code statement may look long and confusing but it is quite simple. We call the Load method of a ContentManager variable named content (created by default). Then we specify for the method that we are loading a Texture2D and that the texture name is “StoneTexture” (for you that will probably be different). That is really all there is to that line.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Drawing the Texture Using the SpriteBatch&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;Finally, we have come to the part where we can display our texture. Using the SpriteBatch class and its Draw method, we can easily draw our texture.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; To &lt;em&gt;draw&lt;/em&gt; a sprite means the same thing as to &lt;em&gt;render&lt;/em&gt; a sprite.&lt;br /&gt;&lt;br /&gt;The first step is to create the SpriteBatch. At the top of the class along with the other variable declarations, create a SpriteBatch:&lt;br /&gt;&lt;summary&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//The SpriteBatch we will use to draw the texture. &lt;/summary&gt;&lt;br /&gt;SpriteBatch spriteBatch;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now, we can initialize it. Inside of the Initialize method, add this code to initialize our SpriteBatch:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Initialize the SpriteBatch.&lt;br /&gt;spriteBatch = new SpriteBatch(graphics.GraphicsDevice);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The constructor for the SpriteBatch needs a GraphicsDevice. We access one by using the GraphicsDevice property inside of our GraphicsDeviceManager variable.&lt;br /&gt;&lt;br /&gt;Since our SpriteBatch has now been created, we can now use it. The following calls to the SpriteBatch class will be placed in the Draw method right after the graphics.GraphicsDevice.Clear(Color.CornflowerBlue); line.&lt;br /&gt;&lt;br /&gt;First, we need to start the SpriteBatch. The reason for doing this is to set any needed parameters for the SpriteBatch. These parameters are things such as allowing the ability to take transparency into account or setting the way the SpriteBatch will sort the sprites. Place this code into the Draw method:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;/*Start the SpriteBatch. Your sprite may contain transparency so we &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:courier new;"&gt;allow Alpha-Blending.*/&lt;br /&gt;spriteBatch.Begin(SpriteBlendMode.AlphaBlend);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Next, we want to draw the sprite. Place this code right after the previous line:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Draw the sprite.&lt;br /&gt;spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;We draw the sprite by calling the Draw method of the SpriteBatch variable. The first parameter is the Texture2D that we want to draw. We pass in texture. The next parameter is the position to draw the sprite at. This value is stored in a Vector2. For us, we specify 0, 0, which means that the origin of the sprite will be drawn at that position. The final parameter is the color to taint the background of the sprite with. We want the sprite to look completely normal so we specify Color.White.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; The default origin of the sprite is at the top-left corner of the sprite. To change this, a different overload of Draw needs to be called.&lt;br /&gt;&lt;br /&gt;Finally, we need to “end” the SpriteBatch. There are two purposes for this. One is that instead of the sprites being drawn at the moment you call the Draw method, they are actually added to a list. Once End is called, all the sprites in the list are drawn at once. This is actually more efficient. The second reason is to reset the different values you changed when you called the Begin method. The different values are changed back to their default value until you call the Begin method again. After the two previous calls to the SpriteBatch, place this final statement:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//End the SpriteBatch.&lt;br /&gt;spriteBatch.End();&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Congratulations! You have now successfully coded a small application that renders a sprite onto the screen. Running the project now should result in your sprite drawn at the top-left corner of the screen (because we specified 0, 0 for the position).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RzugUPcdJmI/AAAAAAAAAI0/JxLGLC4iuI8/s1600-h/StoneTextureRendered.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132872469922522722" style="CURSOR: hand" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RzugUPcdJmI/AAAAAAAAAI0/JxLGLC4iuI8/s400/StoneTextureRendered.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt; After completing this lesson, you should hopefully see a result resembling this screen-shot.&lt;br /&gt;&lt;br /&gt;I do hope that you have been able to solve some confusion by reading this lesson and I fully hope that you can easily continue along with your gaming quest. If you find any errors or mistakes, or if any parts of this lesson were confusing, please post a comment so that I can fix it. Thanks again.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6218175184784256745?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6218175184784256745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6218175184784256745' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6218175184784256745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6218175184784256745'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/how-to-render-sprite-using-spritebatch.html' title='How to Render a Sprite Using the SpriteBatch'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_kLtxSdyLIgE/RzugUfcdJnI/AAAAAAAAAI8/eqveCMh6x4w/s72-c/AddExistingItemSE.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-1029216410845492660</id><published>2007-11-15T17:04:00.001-08:00</published><updated>2007-11-18T18:55:30.279-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Tutorials'/><title type='text'>Tutorials</title><content type='html'>These tutorials I hope can get you going onto a new topic or help you with an unknown subject. If you have any requests, please post a comment. Thanks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The SpriteFont&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-to-print-simple-text-onto-screen.html"&gt;How to Print Simple Text onto the Screen&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2D Textures&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-to-render-sprite-using-spritebatch.html"&gt;How to Render a Sprite Using the SpriteBatch&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I give all the desires of my heart to you, Lord. May you work in everyone's heart so that they will discover the true joy that comes with following you. Amen.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-1029216410845492660?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/1029216410845492660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=1029216410845492660' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1029216410845492660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1029216410845492660'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/tutorials.html' title='Tutorials'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6164763659974037958</id><published>2007-11-15T17:00:00.001-08:00</published><updated>2007-11-15T17:00:39.729-08:00</updated><title type='text'>Methods and Properties</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-size:130%;"&gt;&lt;strong&gt;Basic Method Creation&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;Methods are very useful in the C# language. Methods can help organize and simplify code, and are used all the time in game programming. This lesson should be able to introduce anyone who knows even nothing about programming, to the world of methods and how to create them, use them, and benefit from them in your programming. &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;br /&gt;A method can be looked at like a named container that holds code and does something to a value. This can be useful, for example, if you wanted to explode a ship. Instead of re-writing the code to explode the ship every time there is a collision, you can just create a method that explodes a ship, and then just call that method every time you want a ship to explode.&lt;br /&gt;&lt;br /&gt;First, before we can call a method, we need to learn how to create methods. Here is the method creation structure:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;accessModifier returnType methodName ( parameters )&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First of all, methods need an access modifier. This modifier serves the same purpose as access modifiers on variables.&lt;br /&gt;&lt;br /&gt;Next, there is the return type. The return type shows what type of variable you want the method to return. For example, let’s say that we have created a method called GiveBackEight. This method would look like the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private int GiveBackEight()&lt;br /&gt;{&lt;br /&gt;return 8;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;When we call this method, we want to set any integer to a value of eight. In order to be able to set an integer to the value that the method returns we need to have an int as the parameter type. This way, we can set the value of a variable to the value this method returns by using the command &lt;span style="font-family:courier new;"&gt;int myVariable = GiveBackEight();&lt;/span&gt; This sets the value of myVariable to the value of what GiveBackEight returns.&lt;br /&gt;You can also create a variable that has a return type of, void which means the method does not return anything. These types of methods could be used for example to just draw something. You could declare a method that drew the number eight on the screen like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private void DrawEight()&lt;br /&gt;{&lt;br /&gt;Console.WriteLine("8");&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This just draws the number eight onto the screen. These types of methods don’t give back anything. These types of methods are to do commands that will finish themselves. They are never used to change the value of a variable and give it back because with a void return type, the methods cannot return anything. You can call this method by using a command like &lt;span style="font-family:courier new;"&gt;DrawEight();&lt;/span&gt; This just calls the method to do what it does.&lt;br /&gt;&lt;br /&gt;After the return type, you have the method name, which is just like a variable name, and is used to access the method.&lt;br /&gt;&lt;br /&gt;Finally, you have the parameters, which are placed in parentheses. A parameter is like a value that is given from an outside source so that the method can complete what it needs to do accurately. We have talked about these types of variables in the previous chapter. For example, if we wanted to allow the capability to draw any number, not just eight, we could change the DrawEight method to:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private void DrawNumber(int numberToDraw)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(numberToDraw.ToString());&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code takes any number that you choose as a parameter, and then draws that number. This is very helpful because, instead of having to make a billion different methods to draw every number, you can just create one method that has the capability to draw any number.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Method Overloads&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Sometimes you may want to create the same method, but with maybe a few different parameters. An example of this is, maybe you have an explosion method that explodes at a given intensity value. You may also want to make it where the default intensity value is 100. You could do something like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private void ExlodeShip(int intensity)&lt;br /&gt;{&lt;br /&gt;//Explosion code&lt;br /&gt;}&lt;br /&gt;private void ExplodeShip()&lt;br /&gt;{&lt;br /&gt;ExplodeShip(100);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code first creates the ExplodeShip method. This method takes an int parameter for the intensity of the explosion. Below that method though, we have another method with the same name. This method is an overload of the original ExplodeShip method but takes no parameters. Since 100 is the most common explosion intensity, for most cases the user will just pass in 100 for the intensity value. Instead of making him do that, we create an overload of ExplodeShip that takes no parameters but calls the one-parameter ExplodeShip version and passes in 100 because that is what the user wants. For more complicated methods, this can save a lot of time.&lt;br /&gt;&lt;br /&gt;There are a few things you need to watch out for when using method overloads. You need to be careful not to have a continual loop. This could maybe happen when you on accident call the same method that you are in. For example calling ExplodeShip(); in the zero-parameter method would result in a continual loop because you are inside the method that you are calling.&lt;br /&gt;&lt;br /&gt;Another thing is that you can’t have the method overload have the same parameter types. Even if one overload has int intensity and another method has int timeDelay, you can’t do this because the C# compiler (program that executes the code) will not be able to tell the difference. For it, both overloads have the same parameter types and it won’t know which method to call.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Properties&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;Properties are another type of code-block that you can use in C#. Some people may think properties are really confusing, but they aren’t at all, and are almost exactly the same as methods. You could look at a property like a method that doesn’t have parameters. To create a property, you would do something like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;accessModifier returnType propertyName&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;You can see that this format is almost the same as the method format. We have an access modifier, a return type, and a property name. These all serve the same purpose as for methods.&lt;br /&gt;&lt;br /&gt;There is one exception though. Besides the fact that properties can’t take parameters, they also can’t have the void return type. This is because properties are usually used a little differently than methods. Methods are more used to do things to values and then give the value back. Properties aren’t so much used that way. Properties are more used to give a value or set a value of something. This would explain why you can’t have the void return type because properties can’t just do something; they have to return a value.&lt;br /&gt;&lt;br /&gt;To explain this, you could create this method which would return the value of ten:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private int Ten()&lt;br /&gt;{&lt;br /&gt;return 10;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;You could also create the same thing using a property:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private int Ten&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return 10;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;The property would be the correct way to go. All this property does, is, when you try to access the value of what Ten has, the get part of the property is called. The only difference is that instead of calling &lt;span style="font-family:courier new;"&gt;myInt = Ten();&lt;/span&gt; which is the method version, you call &lt;span style="font-family:courier new;"&gt;myInt = Ten;&lt;/span&gt; which doesn’t use the parentheses because there can be no parameters in a property.&lt;br /&gt;&lt;br /&gt;Properties are mostly used for when you want to access a value in a class. For example the MathHelper class has a property called Pi which gives the value of PI.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Set Properties&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;Set properties are also types of properties that you can use. The way I will explain this is in a game example. Pretend you had a player class. Inside that player class you have a health property that allows access to the health. You would want someone to be able to access the health variable and change it to his liking. You could do this by using this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;private int health;&lt;br /&gt;public int Health&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return health;&lt;br /&gt;}&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;health = value;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First, we declare a private variable called health. This variable allows us to access health in our class when we want to change it or set it to a value.&lt;br /&gt;&lt;br /&gt;After that we have our property called Health (remember variable names are case-sensitive). First we call the get part which returns the value of what our private health variable is. Then we call the set part. This part is called when we set the value of Health using something like &lt;span style="font-family:courier new;"&gt;Health = aValue&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;;&lt;/span&gt;. In this part of the property we set health, our private variable, to value which is the value that we put on the right side of the equal sign when we set Health.&lt;br /&gt;&lt;br /&gt;Since names in C# are case-sensitive, we can make a variable and a property have the same name. Of course, you may think that we can just make the private health variable into a&lt;br /&gt;public one, we won’t have to worry about the property stuff. We could do this, but it would be incorrect programming practice. Also, using properties allows us to change the value of what we return which you can’t do if you just have a public variable. This could look like the following:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;private int health;&lt;br /&gt;public int TenMoreThanHealth&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return health + 10;&lt;br /&gt;}&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;health = value;&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6164763659974037958?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6164763659974037958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6164763659974037958' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6164763659974037958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6164763659974037958'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/methods-and-properties.html' title='Methods and Properties'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-5448592491759162516</id><published>2007-11-15T16:59:00.001-08:00</published><updated>2007-11-18T18:55:57.836-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C# Primer'/><title type='text'>C# Primer</title><content type='html'>Since XNA uses the C# language, I've decided to write some simple lessons on the basics of C#. This way, understanding the XNA code won't have to be so confusing.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/variables.html"&gt;Variables&lt;/a&gt;--Explains about variables and how to use them.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/methods-and-properties.html"&gt;Methods and Properties&lt;/a&gt;--Explains about how to create and call methods and properties.&lt;br /&gt;&lt;br /&gt;I give all the desires of my heart to you, Lord. May you work in everyone's heart so that they will discover the true joy that comes with following you. Amen.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-5448592491759162516?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/5448592491759162516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=5448592491759162516' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5448592491759162516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5448592491759162516'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/c-primer.html' title='C# Primer'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-5228995239506854832</id><published>2007-11-15T16:57:00.000-08:00</published><updated>2007-11-15T16:58:18.839-08:00</updated><title type='text'>Variables</title><content type='html'>&lt;p&gt;&lt;strong&gt;&lt;span style="font-family:trebuchet ms;font-size:130%;"&gt;Creating Variables&lt;/span&gt;&lt;/strong&gt; &lt;p&gt;&lt;span style="font-family:Trebuchet MS;"&gt;Variables are very important in the C# language. Using variables gives you control of many different values. There are tons of different variables that can be used in C# and they all follow a similar pattern; one that we will explain.&lt;/span&gt; &lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;First of all, what is a variable? A variable is named object that can be accessed and manipulated. You can access these values to use them in your project. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;There are three different ways you can declare variables. The first way you can declare a variable is at the top of a class. This allows you to access the variable from any method or property inside of the class. These types of variables can be called class-variables. To declare a class variable, you would try and follow this format:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;accessModifier variableType variableName ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First of all, there is the access modifier. An access modifier is a keyword placed in front of a variable, method or other member, which restricts or allows access to it from some other class or struct. A member is any variable, property, or method inside of a class. The private modifier allows the least amount of access and allows the item to only be accessed inside the class it was created in. The protected modifier allows access only from inherited classes, and the public modifier allows total access from all classes. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;There is also an access modifier named static. The static keyword allows the item it is being applied to, to not be part of a class instance but, instead, related to the class name. This modifier is not used at the moment but will be explained later.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;After the access modifier we have the variable type. Each variable type contains different information needed for that variable type. For example, the int class contains information that holds integers. The string class contains information that holds text, and the bool class contains information that holds true or false values. Each variable type is different but most can be created the same way. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;Then, after the variable type, you can name the variable. Variable names can be anything they want, but they are case-sensitive. &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;p&gt;Finally, you have the semi-colon which you place to signify that you are done creating the variable.&lt;/p&gt;&lt;p&gt;As I told you, there are different ways that you can create a variable. We just looked at the class variable type. There is also another way to create variables. In this way, you create a variable inside a method or property. The difference between these types of variables is that they can only be accessed inside of that method or property. You create these types of variables the same way as a class variable, but you do not place an access modifier because you can’t access the variable outside of the function it was created in. This limit of access is called a variables scope. You would want to create this type of variable like so:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;variableType variableName ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Finally, there is one last way you can create variables. These types of variables are used inside method calls and are called parameters. For example if I called the, Multiply method of a Math class then I could pass in, 5 as an parameter. I wouldn’t name the variable because I can never access it again, and I don’t need any access modifiers, variable type name, or even a semi-colon. All I need is the value of the variable. &lt;/p&gt;&lt;p&gt;There are many different types of variables and their uses can be used in different ways. Here is a list giving a quick description of the variable types and their uses:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;Variable Type; Containment Type; Constructor Type&lt;br /&gt;Int32(int); (-)2,147,483,64(7-8); int intVar;&lt;br /&gt;Int64(long); (-)9,223,372,036,854,775,80(7-8);long longVar;&lt;br /&gt;Byte(byte); 255; byte byteVar;&lt;br /&gt;UInt32(uint); 4,294,967,295; uint uintVar;&lt;br /&gt;Uint64(ulong); 18,446,744,073,709,551,615; ulong ulongVar;&lt;br /&gt;Single(float); (-)7 Digits; float floatVar&lt;br /&gt;Double(double); (-)15-16 Digits; double doubleVar;&lt;br /&gt;Decimal(decimal); (-)28-29 Digits; decimal decimalVar;&lt;br /&gt;String(string); Text between quotes(“”); string stringVar;&lt;br /&gt;Char(char); One Character between symbols(‘’);char charVar;&lt;br /&gt;Boolean(bool); True or False; bool boolVar;&lt;br /&gt;Random; Used for Randomizing; Random rnd = new Random()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Constructor Type shows how you can create a variable of that type. The Random class inherits from the Object class instead of the Type class and needs to be created using the, &lt;span style="font-family:courier new;"&gt;new ClassType(...);&lt;/span&gt; format. This way calls the constructor of that variable. The constructor of a variable is the method that is called to create the variable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Assigning Values to Variables&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;Assigning values to variables is also very important. In order to actually be able to use the variable in your project, you need a way to assign values to it.&lt;/p&gt;&lt;p&gt;The assignment operator is used for assigning values. An operator is a symbol that C# recognizes as a command to do something to a variable(s). You can assign variables using the following structure:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;leftHandVar = rightHandValue ;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First, we place the name of the variable we want to assign a value to. If a variable does not yet have a specified value, then this process is called initializing. A variables initial value is the value it is first set to. You can also initialize a variable at the same time it is created like, &lt;span style="font-family:courier new;"&gt;private int intVar = 4;&lt;/span&gt; If you don’t initialize a variable it will either be set to a default value like zero, or will be set to null, which means no value.&lt;/p&gt;&lt;p&gt;Next we have the equal operator. This operator gets the preceding variable ready to be assigned a value. &lt;/p&gt;&lt;p&gt;Finally, we have the new value we want the variable to be set to.&lt;br /&gt;You can also assign a variable to equal the value of another variable. This could look like, &lt;span style="font-family:courier new;"&gt;intVar = intVar2;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size:130%;"&gt;Modifying Variable Values&lt;/span&gt;&lt;br /&gt;&lt;/strong&gt;After you have assigned a value to a variable, you will probably want to be able to modify that value. For numbers, there are some of the normal math operators that can be used. These operators can be used as such:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;int1 += 10;&lt;br /&gt;int1 -= 10;&lt;br /&gt;int1 *= 10;&lt;br /&gt;int1 /= 10;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;These operators change the values of variables. The &lt;span style="font-family:courier new;"&gt;+=&lt;/span&gt; means the same thing as, &lt;span style="font-family:courier new;"&gt;int1 = int1 + 10;&lt;/span&gt; You can also modify the right hand value by doing something like, &lt;span style="font-family:courier new;"&gt;int1 += 10 * 3&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-5228995239506854832?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/5228995239506854832/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=5228995239506854832' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5228995239506854832'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5228995239506854832'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/variables.html' title='Variables'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-5334250595153076157</id><published>2007-11-15T16:52:00.000-08:00</published><updated>2007-11-17T14:35:00.773-08:00</updated><title type='text'>What are all the possible font names that you can use for a SpriteFont?</title><content type='html'>&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; What are all the possible font names that you can use for a SpriteFont?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Microsoft has allowed almost all the font families to be used for a SpriteFont. If you are having problems though, take not that there are some standards that need to be used in order to have XNA recognize the font family name.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;You need to allow spaces which may seem odd but is needed (i.e. the font family Times New Roman would still be entered in as “Times New Roman” and not “TimesNewRoman”).&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Also, obviously you need to spell the name correctly. No little mistakes as every letter matters. Also, there is no abbreviating.&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;The Algerian font family is not accepted.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-5334250595153076157?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/5334250595153076157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=5334250595153076157' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5334250595153076157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5334250595153076157'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/question-what-are-all-possible-font.html' title='What are all the possible font names that you can use for a SpriteFont?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-3472453843606508872</id><published>2007-11-15T16:50:00.000-08:00</published><updated>2007-11-17T14:35:22.772-08:00</updated><title type='text'>How can I vibrate an Xbox 360 controller?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; How can I vibrate an Xbox 360 controller?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer:&lt;/strong&gt; Vibrating an Xbox 360 controller is actually quite simple. All you need to do is call the SetVibration method of the static GamePad class.&lt;br /&gt;&lt;br /&gt;To vibrate a controller, you don’t actually need a GamePadState to work with because all you have to do is call GamePad.SetVibration(…). For our sake though, we will create a GamePadState just so that we can check if certain buttons are down and then vibrate the controller respectively. Create a GamePadState at the top of the Update method.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//The GamePad to check for input from.&lt;br /&gt;GamePadState gamePad = GamePad.GetState(PlayerIndex.One);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now, for a simple effect, whenever you are pressing the A button, the left motor of the controller vibrates and whenever you are pressing the B button, the right motor of the controller vibrates. To do this, place this code also into the Update method.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Create two variables to keep track of the rotation values of the &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:courier new;"&gt;//motors.&lt;br /&gt;float leftMotorVibration = 0;&lt;br /&gt;float rightMotorVibration = 0;&lt;br /&gt;&lt;br /&gt;//If A is pressed, vibrate the left motor.&lt;br /&gt;if (gamePad.Buttons.A == ButtonState.Pressed)&lt;br /&gt;{&lt;br /&gt;leftMotorVibration = 1;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;leftMotorVibration = 0;&lt;br /&gt;}&lt;br /&gt;//If B is pressed, vibrate the right motor.&lt;br /&gt;if (gamePad.Buttons.B == ButtonState.Pressed)&lt;br /&gt;{&lt;br /&gt;rightMotorVibration = 1;&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;rightMotorVibration = 0;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;//Finally, vibrate the motors based on their individual values.&lt;br /&gt;GamePad.SetVibration(PlayerIndex.One, leftMotorVibration,&lt;br /&gt;rightMotorVibration);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;First we create two simple floats to keep track of the vibration value of the motors. After that we check for input. Note that we have to check if the buttons are not pressed along with if they are pressed. This is because, if the buttons were pressed and then were released, nothing ever sets the vibration back to zero. Finally, after checking for input, we call the SetVibration method of the GamePad class. The first parameter specifies the player controller to vibrate which for us was Player 1. The second and third parameters specify the amount to rotate the motors by. For us we passed in leftMotorVibration and rightMotorVibration.&lt;br /&gt;&lt;br /&gt;If you run the project now and press A or B, Player 1’s game controller should vibrate accordingly.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-3472453843606508872?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/3472453843606508872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=3472453843606508872' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3472453843606508872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3472453843606508872'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/question-how-can-i-vibrate-xbox-360.html' title='How can I vibrate an Xbox 360 controller?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-4750775550028797166</id><published>2007-11-15T16:45:00.000-08:00</published><updated>2007-11-15T16:46:23.556-08:00</updated><title type='text'></title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Question:&lt;/strong&gt; How do I tint the color of a Texture2D using the SpriteBatch?&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Answer:&lt;/strong&gt; To tint the color of a Texture2D when using the Draw call of a SpriteBatch, you need to change the Color parameter. For example, to tint the background of a sprite to the color orange, you would make this call in the Draw method:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;spriteBatch.Draw(myTexture, new Vector2(0, 0), &lt;strong&gt;Color.Orange&lt;/strong&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The Color.Orange parameter is the important parameter. This tells the SpriteBatch to draw the texture with an overall orange-ish background. An example of the same texture drawn twice is shown below: &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RzpXkPzVo8I/AAAAAAAAAIM/IH3qOd1OTOQ/s1600-h/FacePicture.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132511005570868162" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RzpXkPzVo8I/AAAAAAAAAIM/IH3qOd1OTOQ/s400/FacePicture.jpg" border="0" /&gt;&lt;/a&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RzpXj_zVo7I/AAAAAAAAAIE/8A1lvs4Om0I/s1600-h/OrangeFacePicture.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5132511001275900850" style="CURSOR: hand" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RzpXj_zVo7I/AAAAAAAAAIE/8A1lvs4Om0I/s400/OrangeFacePicture.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; On the left there is the texture drawn with a white background. On the left, the same texture is drawn with an orange background.&lt;br /&gt;&lt;br /&gt;The same texture was drawn once with Color.White. This value specifies that you want no changes to the background of the texture (i.e. if the original background was blue and you specified Color.White, the background would stay blue). Then the texture was drawn with Color.Orange. This drew the sprite with an orange-ish color. Note that if the original background was blue, the background would not turn orange, but instead the blue background would be mixed with the orange color to create a new, odd color.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-4750775550028797166?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/4750775550028797166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=4750775550028797166' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4750775550028797166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4750775550028797166'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/question-how-do-i-tint-color-of.html' title=''/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_kLtxSdyLIgE/RzpXkPzVo8I/AAAAAAAAAIM/IH3qOd1OTOQ/s72-c/FacePicture.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-8080013780416578132</id><published>2007-11-15T16:43:00.000-08:00</published><updated>2007-11-22T19:55:04.091-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Question and Answer'/><title type='text'>Question and Answer</title><content type='html'>Hopefully, these question and answer posts will help you. If you have a question that is not answered, please post a comment and ask for it to be answered.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The SpriteFont&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/question-what-are-all-possible-font.html"&gt;What are all the possible font names that you can use for a SpriteFont?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Xbox 360 Controller&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/question-how-can-i-vibrate-xbox-360.html"&gt;How can I vibrate an Xbox 360 controller?&lt;/a&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-can-i-check-to-see-if-xbox-360.html"&gt;How can I check to see if an controller button is down?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Keyboard&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-can-i-see-if-key-is-down-or-not.html"&gt;How can I check if a key is down or not?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The Content Pipeline&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/what-are-all-possible-texture-file.html"&gt;What are all the possible texture file types that can be used?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Drawing 2D Textures With the SpriteBatch&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/question-how-do-i-tint-color-of.html"&gt;How do I tint the color of a Texture2D using the SpriteBatch?&lt;/a&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/question-how-do-i-scale-size-of-sprite.html"&gt;How do I scale the size of a sprite?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;2D Rectangles&lt;/strong&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-do-i-build-rectangle-around-object.html"&gt;How do I build a rectangle around an object?&lt;/a&gt;&lt;br /&gt;&lt;a href="http://christiangameprogramming.blogspot.com/2007/11/how-do-i-check-if-two-rectangles-are.html"&gt;How do I check if two rectangles are overlapping?&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I give all the desires of my heart to you, Lord. May you work in everyone's heart so that they will discover the true joy that comes with following you. Amen.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-8080013780416578132?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/8080013780416578132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=8080013780416578132' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8080013780416578132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8080013780416578132'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/11/question-and-answer.html' title='Question and Answer'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-565546489106161008</id><published>2007-09-09T17:34:00.000-07:00</published><updated>2007-09-09T17:39:34.540-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 8 -- Keyboard Key Presses and Mouse Clicks</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial shows you how to track keyboard key presses and mouse button clicks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Knowledge of &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/tutorial-7-advanced-sprite-drawing.html"&gt;Tutorial 7&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Read the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/handling-keyboard-key-presses-and-mouse.html"&gt;Tutorial 8&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You don't get to Heaven by what you do, but by what you believe.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-565546489106161008?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/565546489106161008/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=565546489106161008' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/565546489106161008'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/565546489106161008'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-8-keyboard-key-presses-and.html' title='Tutorial 8 -- Keyboard Key Presses and Mouse Clicks'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-3527298162207417293</id><published>2007-09-09T11:59:00.001-07:00</published><updated>2007-09-09T17:34:06.269-07:00</updated><title type='text'>Handling Keyboard Key Presses and Mouse Clicks</title><content type='html'>&lt;span&gt;&lt;/span&gt;In this tutorial, I want to talk about how you can handle keyboard key presses and mouse button clicks. You already know how to track if a keyboard key or mouse button is down, but a lot of input checks need to only occur if a key is presses or a button is clicked.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Keyboard Key Presses&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;What we need to do is keep a KeyboardState variable, that actually contains the data for the last Update loop. That way, if we need to have a check for key being down, all we have to do is make sure the current keyboard state is not equal to the last keyboard state. Then, after each Update, we set the value of the old keyboard to the value of the new keyboard. You may see how this works once we get started.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1: Create an Old Keyboard State Variable&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;First we need to create a variable that holds the old state of the keyboard. Create this variable in the fields are:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;KeyboardState&lt;/span&gt; myOldKeyboard = &lt;span style="color:#66cccc;"&gt;Keyboard&lt;/span&gt;.GetState();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As you see here, we are creating a keyboard state variable and naming it &lt;em&gt;myOldKeyboard&lt;/em&gt;. Also, we are intializing it right now. This is because we are not going to initialize it at the beginning of the first update loop, so we should initialize it now. This is only going to matter if a key happens to be pressed right when the project starts(which would have to be in like the first 1.6 milliseconds or so).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2: Update the Old KeyboardState at the End Of The Update Method&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now we need to update &lt;em&gt;oldKeyboard&lt;/em&gt; at the end of the &lt;em&gt;Update&lt;/em&gt; method. This is because, if a key happens to be pressed, and we don't keep track of that in the old KeyboardState variable, then &lt;em&gt;oldKeyboard&lt;/em&gt; will not be exactly correct.&lt;br /&gt;&lt;br /&gt;To update the old keyboard to the old state of the real keyboard, put this line at the end of the &lt;em&gt;Update&lt;/em&gt; method:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myOldKeyboard = myKeyboard;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All this does is set the value of the &lt;em&gt;oldKeyboard&lt;/em&gt;, to the value of the current keyboard(&lt;em&gt;myKeyboard&lt;/em&gt;), which is actually old because it is used at the end of the &lt;em&gt;Update&lt;/em&gt; method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; When I say, "&lt;em&gt;the end of the Update method&lt;/em&gt;", I always mean at the bottom of the &lt;em&gt;Update&lt;/em&gt; method, but above the &lt;em&gt;base.Update&lt;/em&gt; line.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 3: Test Key Presses&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now we get to test if what we have done so far actually works. In order to track a keyboard key press, we will check if the space bar is pressed. If the space bar has been pressed, we will taint our first sprite with a color of blue. If the space bar is pressed again, we will take the blue off of the color.&lt;br /&gt;&lt;br /&gt;Put this code underneath the other keyboard input code for our first sprite:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myKeyboard.IsKeyDown(&lt;span style="color:#66cccc;"&gt;Keys&lt;/span&gt;.Space) &amp;&amp;amp;&lt;br /&gt;myOldKeyboard.IsKeyUp(&lt;span style="color:#66cccc;"&gt;Keys&lt;/span&gt;.Space))&lt;br /&gt;{&lt;br /&gt;     spriteColored = !spriteColored;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr8I/AAAAAAAAAHc/AOG3NSMy7us/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5108364879338188738" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr8I/AAAAAAAAAHc/AOG3NSMy7us/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-1 The Code to Track a Key Press&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;First this code checks if currently, the space bar is pressed. Since &lt;em&gt;myKeyboard&lt;/em&gt; is always set to the current state of the keyboard at the beginning of the&lt;em&gt; Update&lt;/em&gt; method, if the space bar is pressed, this will be true. Then we also check(using the and(&amp;&amp;amp;) operator) if the old state of the keyboard, which was set to a value at the end of the &lt;strong&gt;last&lt;/strong&gt; &lt;em&gt;Update&lt;/em&gt; call, does not have the space bar pressed. If both of these if checks return true, then we set a variable called &lt;em&gt;spriteColored&lt;/em&gt; to its opposite. Now we just need to create this variable in the fields area:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;bool&lt;/span&gt; spriteColored = &lt;span style="color:#3333ff;"&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This creates a bool(a class that can have a value of either true or false) variable and initializes it with a value of false so that the sprite will start out normal.&lt;br /&gt;&lt;br /&gt;Now we just need to make the sprite appear blue when &lt;em&gt;spriteColored&lt;/em&gt; equals true.&lt;br /&gt;&lt;br /&gt;In our &lt;em&gt;Draw&lt;/em&gt; method, locate the call that draws the first sprite. Delete that and replace it with this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteColored)&lt;br /&gt;{&lt;br /&gt;mySpriteBatch.Draw(myTexture, spritePosition, &lt;strong&gt;&lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.Blue&lt;/strong&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;else&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;mySpriteBatch.Draw(myTexture, spritePosition, &lt;strong&gt;&lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White&lt;/strong&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This draws the sprite with a blue color if &lt;em&gt;spriteColored&lt;/em&gt; equals true, and white if not. We use the else statement to signal that if &lt;em&gt;spriteColored&lt;/em&gt; equals false, then the code inside the else statement will be executed.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr9I/AAAAAAAAAHk/mzYvpXhyBi8/s1600-h/ScreenShot2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5108364879338188754" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr9I/AAAAAAAAAHk/mzYvpXhyBi8/s400/ScreenShot2.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1-2 Drawing Our Sprite Blue If SpriteColored Equals True&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; Instead of using &lt;em&gt;if(spriteColored == true)&lt;/em&gt;, I can just put, &lt;em&gt;if(spriteColored)&lt;/em&gt;. Also, &lt;em&gt;if(spriteColored == false)&lt;/em&gt; is the same as &lt;em&gt;if(!spriteColored)&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;Now run the project. You should be able to press the space bar and the sprite will turn blue. You can press it again and the sprite will turn back to white.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr-I/AAAAAAAAAHs/h9HuHWQG9Uc/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5108364879338188770" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr-I/AAAAAAAAAHs/h9HuHWQG9Uc/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-3 The Sprite When it is Blue&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;That is how you keep track of a key press. Now time to check for mouse clicks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Handling Mouse Button Clicks&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Handling mouse clicks goes pretty much the same as handling keyboard key presses. To show when a mouse button is clicked, we will flip the second sprite using its SpriteEffects parameter when the right mouse button is clicked.&lt;br /&gt;&lt;br /&gt;First, just like the KeyboardState variable, create a MouseState variable and initialize it:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;MouseState&lt;/span&gt; myOldMouse = &lt;span style="color:#66cccc;"&gt;Mouse&lt;/span&gt;.GetState();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then, at the bottom of the Update method, set it so that it always has the current, old value of the keyboard. In other words, so that it always is one &lt;em&gt;Update&lt;/em&gt; method behind.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myOldMouse = myMouse;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Now we can check if the right button is clicked. Put this code under the mouse input code for the second sprite:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myMouse.RightButton == &lt;span style="color:#66cccc;"&gt;ButtonState&lt;/span&gt;.Pressed &amp;&amp;amp; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myOldMouse.RightButton == &lt;span style="color:#66cccc;"&gt;ButtonState&lt;/span&gt;.Released)&lt;br /&gt;{&lt;br /&gt;sprite2Flipped = !sprite2Flipped;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Create the &lt;em&gt;sprite2Flipped&lt;/em&gt; bool in the fields area:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3366ff;"&gt;bool&lt;/span&gt; sprite2Flipped = &lt;span style="color:#3366ff;"&gt;false&lt;/span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Finally, flip the sprite when &lt;em&gt;sprite2Flipped&lt;/em&gt; equals true. Delete the code that draws the second sprite and replace it with this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(sprite2Flipped)&lt;br /&gt;{&lt;br /&gt;mySpriteBatch.Draw(myTexture2, spritePosition2, &lt;span style="color:#3333ff;"&gt;null&lt;/span&gt;,&lt;span style="color:#66cccc;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White, 0, &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;(myTexture2.Width / 2,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myTexture2.Height / 2), 1, &lt;strong&gt;&lt;span style="color:#66cccc;"&gt;SpriteEffects&lt;/span&gt;.FlipHorizontally&lt;/strong&gt;,&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;0); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;else&lt;/span&gt;&lt;br /&gt;{ &lt;span style="color:#66cccc;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Draw(myTexture2, spritePosition2, &lt;span style="color:#3333ff;"&gt;null&lt;/span&gt;, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White, 0, &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;(myTexture2.Width / 2, &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;myTexture2.Height / 2), 1, &lt;span style="color:#66cccc;"&gt;SpriteEffects&lt;/span&gt;.None, 0);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code flips the sprite horizontally when &lt;em&gt;sprite2Flipped&lt;/em&gt; equals true, and doesn't when &lt;em&gt;sprite2Flipped&lt;/em&gt; is false. Now you can run the project. You should be able to click the right mouse button and the sprite should flip horizontally.&lt;br /&gt;&lt;br /&gt;Now you know how to track keyboard key presses and mouse button clicks.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RuSOy-AIr_I/AAAAAAAAAH0/9uUHXk-Pu2E/s1600-h/ScreenShot4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5108364883633156082" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RuSOy-AIr_I/AAAAAAAAAH0/9uUHXk-Pu2E/s400/ScreenShot4.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-4 The Sprite When it is Flipped&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you have any requests or questions, please post a comment and I will try to answer. Thanks for reading the tutorial.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember:&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You don't get to Heaven by what you do, but by what you believe.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-3527298162207417293?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/3527298162207417293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=3527298162207417293' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3527298162207417293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3527298162207417293'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/handling-keyboard-key-presses-and-mouse.html' title='Handling Keyboard Key Presses and Mouse Clicks'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_kLtxSdyLIgE/RuSOyuAIr8I/AAAAAAAAAHc/AOG3NSMy7us/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6348643764146763941</id><published>2007-09-08T16:56:00.000-07:00</published><updated>2007-09-08T17:44:28.300-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 7 -- Advanced Sprite Drawing</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial talks about the different parameters used in the different method overloads of spriteBatchVariable.Draw. This tutorial also talks about what method overloads are.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A sprite drawn on the screen.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Read the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/advanced-sprite-drawing.html"&gt;Tutorial 7&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Be a hero: Don't conform; Be selfless; Make a difference&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6348643764146763941?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6348643764146763941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6348643764146763941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6348643764146763941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6348643764146763941'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-7-advanced-sprite-drawing.html' title='Tutorial 7 -- Advanced Sprite Drawing'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-5546095634117481597</id><published>2007-09-07T17:18:00.000-07:00</published><updated>2007-09-08T17:06:17.428-07:00</updated><title type='text'>Advanced Sprite Drawing</title><content type='html'>&lt;div align="left"&gt;In this tutorial, I will talk about how you can draw a sprite with more effects applied to the sprite than just a color to taint the sprite with.&lt;br /&gt;&lt;br /&gt;What we need to do is call the draw method of the our SpriteBatch variable, but just fill in a few more parameters.&lt;br /&gt;&lt;br /&gt;You may ask, "&lt;em&gt;But how can a method have different amounts of parameters and still be the same method?&lt;/em&gt;". This is possible with a thing called overloading. If you overload a method, you create a method with the same name as the method you are overloading, but you create the method so that it takes a different amount of parameters. Method overloading is useful for making it easier for the user to use the method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Example:&lt;/strong&gt; Pretend you have a method that explodes a ship called &lt;em&gt;Explode&lt;/em&gt;. This method needs a Ship class as a parameter so that it can explode that ship and an intensity for the ship to explode at.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;//This is the original method&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#3333ff;"&gt;void&lt;/span&gt; Explode(&lt;span style="color:#66cccc;"&gt;Ship&lt;/span&gt; shipVariable, &lt;span style="color:#3333ff;"&gt;int&lt;/span&gt; explosionIntensity)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:#009900;"&gt;//Code that explodes the ship.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;For your game, 99/100 explosions occur with a 100/1000 intensity. Method overloading comes in here. For that 1 ship that needs a 200/1000 intensity explosion, you have the orginal &lt;em&gt;Explode&lt;/em&gt; method which allows you to pass in the ship to explode, and the intensity of the explosion. But now you want an easier way to explode you 99 ships that all have a 100/1000 intensity explosion. You can create an overload of the &lt;em&gt;Explode&lt;/em&gt; method that only takes one parameter, the ship to explode, and then passes in 100 as a default value for the intensity:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;//Overload of original Explode method&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#3333ff;"&gt;void&lt;/span&gt; Explode(&lt;span style="color:#66cccc;"&gt;Ship&lt;/span&gt; shipVariable)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color:#009900;"&gt;//Call the other Explode method and pass in the &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;//shipVariable it got as a parameter, and then 100 as the&lt;br /&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;default explosion intensity&lt;br /&gt;&lt;/span&gt;Explode(shipVariable, 100);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;You can see how method overloading makes it easier for the user to use the method because now, since 99/100 of your ships use the default explosion intensity which is 100/1000, instead of always calling &lt;em&gt;Explode(shipVariable, 100);&lt;/em&gt;, you can just call &lt;em&gt;Explode(shipVariable);&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;I hope that made sense to you but if you don't get it you may get it more along the tutorial or sometime later.&lt;br /&gt;&lt;br /&gt;Now, since I explained all that to you, I am going to show you where it is actually used.&lt;br /&gt;&lt;br /&gt;In the &lt;em&gt;mySpriteBatch.Draw&lt;/em&gt; call we passed in three parameters, a Texture2D to draw, a Vector2 position, and a Color to taint the sprite with. This was good for our purpose because we didn't really want to change anything on the sprite. Well, now we do want to change the attributes of the sprite. The &lt;em&gt;Draw&lt;/em&gt; method of the SpriteBatch class has several overloads. In fact, you can see all the overloads by typing or re-typing the first parenthesis of the &lt;em&gt;Draw&lt;/em&gt; method call. A tan box should appear(we used this in the second tutorial), but this time we will use this to find how many overloads the method has. In the top right corner you can see &lt;em&gt;1 of 7&lt;/em&gt;. This shows that you are on method overload one out of seven different method overloads. If you push the up or down arrow keys you can see what parameters are needed for this method overload. If you haven't found for yourself by now, we are currently using method overload two. This takes a Texture2D, a Vector2, and a Color.&lt;br /&gt;&lt;/div&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RuM0y-AIr3I/AAAAAAAAAG0/6Od_kDjBgpo/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5107984452609945458" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RuM0y-AIr3I/AAAAAAAAAG0/6Od_kDjBgpo/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 1-1 The Tan Box Showing the Current Method Overload and Parameters Needed&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;For what we want to do we will use overload number six which is one of the overloads that allows the most options to change the way the sprite is drawn. I will explain what all of the overloads we are using mean, and then I will get along with the code.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Texture2D texture&lt;/strong&gt;&lt;br /&gt;This parameter is asking for the texture to draw on the screen.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; There is no default, you have to give the texture in all overloads.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Vector2 position&lt;/strong&gt;&lt;br /&gt;This parameter is asking for the position to draw the sprite on the screen at.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; There is no default, you have to give the position in all overloads. In some cases you may use a rectangle that holds the position instead though.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Rectangle sourceRectangle&lt;/strong&gt;&lt;br /&gt;This parameter is asking for the rectangle out of the texture you want to draw. For example. pretend you have a texture that has all the button images in the game on it. If you wanted to draw only one part of that image, you would specify the size and position for that rectangle to be at on the texture. If you want to use the whole image, you can pass in null instead which means nothing so the whole image whill be drawn.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; &lt;em&gt;null&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;&lt;strong&gt;Color color&lt;br /&gt;&lt;/strong&gt;This parameter specifies what color to taint the sprite with, i.e. orange maybe if the sprite is the player and blue if the sprite is any enemy.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; There is no default, you have to give the color in all overloads. If you don't want any color to be applied to your sprite though, then just use &lt;em&gt;Color.White&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;float rotation&lt;br /&gt;&lt;/strong&gt;This parameter specifies how much you want the sprite to be rotated by.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; 0.0f&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Vector2 origin&lt;/strong&gt;&lt;br /&gt;This parameter specifies the main point for the sprite. If the origin is the center of the sprite, when you draw the sprite, the sprite will be drawn around the center point which means the position you specify for the sprite to be drawn at will refer to the center of the sprite.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; 0, 0 (the top left corner)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;float scale &lt;/strong&gt;&lt;br /&gt;This parameter sets how much you want the sprite to be scaled by.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; 1 (if you put 0 the sprite will end up as small as nothing because you are multiplying your sprites original size by zero which always gives zero.)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;SpriteEffects effects&lt;/strong&gt;&lt;br /&gt;This parameter specifies which type of sprite effects you want applied to your image. You can flip horizontally, vertically, or just do nothing.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; &lt;em&gt;SpriteEffects.None&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;float layerDepth&lt;/strong&gt;&lt;br /&gt;This parameter specifies the depth position of your sprite. This is useful for making certain sprites appear on top of eachother.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Default value:&lt;/strong&gt; It depends on which order your sprite is drawn at out of all the other sprites. Sometimes the last sprite drawn appears on top of the others and sometimes the sprite drawn first appears on top. It depends on which sort mode you pass into the second or third overload of &lt;em&gt;spriteBatchVariable.Begin&lt;/em&gt;. We are not using the second or third overload so the default value is &lt;em&gt;SpriteSortMode.BackToFront&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;That was the last parameter for the overload of &lt;em&gt;Draw&lt;/em&gt; that we are using. Now we can get to some code. You can mostly test the different parameters on your own, I don't have to explain what they do because you can probably figure out, but, I will show you a few things.&lt;br /&gt;&lt;br /&gt;First run your project. Now click the mouse and the sprite should move to that position. If you look closely though, you will see that the top left corner of the sprite is going to the position where you clicked. That is because we are not specifying an origin for the sprite. If we want to change where the sprite goes to, you must change the origin for that sprite.&lt;br /&gt;&lt;br /&gt;Change the call to draw the second texture to look like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Draw(myTexture2, spritePosition2, &lt;span style="color:#3333ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White, 0, &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;.Zero, 1, &lt;span style="color:#66cccc;"&gt;SpriteEffects&lt;/span&gt;.None, 0); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code draws the exact same thing we had before. All the parameter values we have now are the default values they would been. This is not so useful to us now, until we want to change anything.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; In the code above, we used &lt;em&gt;Vector2.Zero&lt;/em&gt; which is accesssing a value that the Vector2 class has in it. This is the same as using &lt;em&gt;new Vector2(0, 0);&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Now we can actually do something. Since our origin is still 0, 0, the sprite will still be drawn with the top-left corner of the sprite drawn at &lt;em&gt;spritePosition2&lt;/em&gt;. Instead of using &lt;em&gt;Vector2.Zero&lt;/em&gt; for our origin parameter, we will use this: &lt;em&gt;new Vector2(myTexture2.Width / 2, myTexture2.Height / 2);&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;This gives our sprite an origin that refers to the center of the sprite.&lt;br /&gt;&lt;br /&gt;Now run the project. If you press the left mouse button, the sprite will be moved to where you clicked but the center of the sprite will be moved to the position of the mouse.&lt;br /&gt;&lt;br /&gt;For the next test, I will show you how to use the source rectangle. For this rectangle, you are specifying what part of the texture you want to be drawn. For an example, just put this line instead of &lt;em&gt;null&lt;/em&gt;: &lt;em&gt;new Rectangle(0, 0, 50, 50);&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;This is creating a rectangle that starts from the top left corner of your texture, and has a width and height of 50 pixels. Run the project now. You should see only a 50 pixel square of the texture.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RuM0y-AIr4I/AAAAAAAAAG8/GQ1JS7VNX40/s1600-h/ScreenShot2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5107984452609945474" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RuM0y-AIr4I/AAAAAAAAAG8/GQ1JS7VNX40/s400/ScreenShot2.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-2 The Source Rectangle Example&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;That was just an example, so change the source rectangle parameter back to &lt;em&gt;null&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;For the last example, I will show you how to rotate the sprite correctly. You may think, "Well all I have to do is type in a number and the sprite will rotate by that many degrees."&lt;br /&gt;&lt;br /&gt;This is incorrect thinking. When you type in a number, the sprite is not rotated in degrees. Type in, 45, for the rotation value. You should see that the sprite is not rotated by 45 degrees, but in radians. Now type in this instead: &lt;em&gt;MathHelper.ToRadians(45);&lt;/em&gt; This draws your sprite at a rotation relative to the number you put in. Now run the project. You should see the sprite is rotated exactly by 45 degrees.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; When you put in, 45, as a parameter for the &lt;em&gt;ToRadians&lt;/em&gt; method, you are not actually drawing the sprite in degrees. Whats happening is, you are converting a value that is in degrees, into a value in radians. You can also use &lt;em&gt;MathHelper.ToDegrees(MathHelper.ToRadians(45))&lt;/em&gt; which converts a radian value into a degree again.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr5I/AAAAAAAAAHE/NUcBzA50WPg/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5107984456904912786" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr5I/AAAAAAAAAHE/NUcBzA50WPg/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-3 The Correctly Rotated Sprite&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Again, erase the value for rotation and put 0&lt;em&gt;.&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Now you know a little more about how sprites are drawn. You also know about method overloading.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr6I/AAAAAAAAAHM/vn96t-l0qy4/s1600-h/ScreenShot4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5107984456904912802" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr6I/AAAAAAAAAHM/vn96t-l0qy4/s400/ScreenShot4.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-4 The Code That Draws the Second Texture&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr7I/AAAAAAAAAHU/D0wjuzjCmpM/s1600-h/ScreenShot5.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5107984456904912818" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RuM0zOAIr7I/AAAAAAAAAHU/D0wjuzjCmpM/s400/ScreenShot5.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-5 The Complete Tutorial. Nothing Much Different That You Can See&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you want you can change the values of other parameters to see what they do. Make sure to change everything back to the way it is now though, when you are done testing.&lt;br /&gt;&lt;br /&gt;If you have any questions or requests, please post a comment and I will try to answer.&lt;br /&gt;&lt;br /&gt;Thanks for reading the tutorial.&lt;br /&gt;&lt;br /&gt;Be a hero: Don't conform; Be selfless; Make a difference&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-5546095634117481597?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/5546095634117481597/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=5546095634117481597' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5546095634117481597'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/5546095634117481597'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/advanced-sprite-drawing.html' title='Advanced Sprite Drawing'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_kLtxSdyLIgE/RuM0y-AIr3I/AAAAAAAAAG0/6Od_kDjBgpo/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6431162573948678195</id><published>2007-09-04T20:48:00.000-07:00</published><updated>2007-09-08T17:45:04.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 6 -- Mouse Input</title><content type='html'>&lt;strong&gt;Introduction &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In this tutorial you will learn how to move a sprite to a certain position based on where the mouse is pressed at. You will learn how to check for rectangle collisions using a new method called the &lt;em&gt;Intersects&lt;/em&gt; method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Knowing how to load a Texture2D with an image.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Read the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/mouse-input.html"&gt;Tutorial 6&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If something bad happens, do you really think God does &lt;strong&gt;not&lt;/strong&gt; have it under control?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6431162573948678195?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6431162573948678195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6431162573948678195' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6431162573948678195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6431162573948678195'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-6-mouse-input.html' title='Tutorial 6 -- Mouse Input'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-7214849789729978819</id><published>2007-09-04T18:14:00.000-07:00</published><updated>2007-09-04T20:47:45.573-07:00</updated><title type='text'>Mouse Input</title><content type='html'>&lt;div align="left"&gt;In this tutorial, I want to introduce mouse input. What this tutorial will teach is how to move a sprite to a certain position based on the mouse position.&lt;br /&gt;&lt;br /&gt;For this tutorial., we will use a new image. Start off the project by adding an image through the Solution Explorer(remember Add--&gt; Existing Item).&lt;br /&gt;&lt;br /&gt;Now create a Texture2D variable and initialize it with your image that you loaded into your project(remember &lt;em&gt;content.Load&lt;/em&gt; etc...) I will name my variable &lt;em&gt;myTexture2&lt;/em&gt;;&lt;br /&gt;&lt;br /&gt;Create a Vector2 variable named &lt;em&gt;spritePosition2&lt;/em&gt; and initialize it with a value of 400, 300. This is so that it will appear in a different position then the first texture we have, which is at position 0, 0.&lt;br /&gt;&lt;br /&gt;Finally, call &lt;em&gt;mySpriteBatch.Draw&lt;/em&gt; under the call for our first texture and draw &lt;em&gt;myTexture2&lt;/em&gt;(really you can put the &lt;em&gt;mySpriteBatch.Draw&lt;/em&gt; call anywhere as long as it is in between the &lt;em&gt;mySpriteBatch.Begin&lt;/em&gt; and &lt;em&gt;mySpriteBatch.End&lt;/em&gt; calls). Pass in &lt;em&gt;spritePosition2&lt;/em&gt; for the position to draw the sprite at.&lt;br /&gt;&lt;/div&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/Rt4lsuAIr1I/AAAAAAAAAGk/Jl_0Cjxsjtk/s1600-h/ScreenShot2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106560477677793106" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/Rt4lsuAIr1I/AAAAAAAAAGk/Jl_0Cjxsjtk/s400/ScreenShot2.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-1 The Call to Draw the Second Texture&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now run the project. You should get a result looking something like this:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/Rt4kteAIrvI/AAAAAAAAAF0/dZCKLzDJi-Y/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106559391051067122" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/Rt4kteAIrvI/AAAAAAAAAF0/dZCKLzDJi-Y/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-2 The Newly Drawn Texture&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now we can move on to what the tutorial is supposed to do. Follow these steps.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1: Create a variable to keep track of mouse input. &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Step 2: Check if the mouse left button is pressed. &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Step 3: Move the sprite to the position of the mouse.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1: Create a variable to keep track of mouse input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Just like the KeyboardState variable we used to check for keyboard input, Microsoft gives us a MouseState variable to keep track of mouse input. Create a MouseState variable and name it &lt;em&gt;myMouse&lt;/em&gt;. Now initialize the variable in the &lt;em&gt;Update&lt;/em&gt; method underneath where we have all our other code except the &lt;em&gt;base.Update&lt;/em&gt; call. We initialize(or more often re-set the value of) the variable by using the command &lt;em&gt;myMouse = Mouse.GetState();&lt;/em&gt; I wanted to initialize the variable underneath all our other code because we will check for mouse input underneath all the other code and I wanted to keep the code for moving the second sprite all kind of in one general area.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2: Check if the mouse left button is pressed&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In order to check if the mouse left button is pressed, place this statement underneath the &lt;em&gt;myMouse = Mouse.GetState()&lt;/em&gt; call;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myMouse.LeftButton == &lt;span style="color:#66cccc;"&gt;ButtonState&lt;/span&gt;.Pressed)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code checks if the left button of the mouse is pressed. We check for the left button of the mouse using the command &lt;em&gt;mouseStateVariable.LeftButton&lt;/em&gt;. Then we check if it is pressed by using the command &lt;em&gt;== ButtonState.Pressed&lt;/em&gt;. The == operator is not the same as the = operator. The = operator &lt;strong&gt;assigns&lt;/strong&gt; values to variables while the == operator &lt;strong&gt;checks&lt;/strong&gt; the values of variables. The == operator can only be used in if statements.&lt;br /&gt;Now we have checked if the left button of the mouse is pressed.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; We are checking if the left button of the mouse is currently pressed, not clicked which means pressed and then released. We will discuss how to do check if the left button of the mouse is clicked in a following tutorial.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/Rt4ktuAIrxI/AAAAAAAAAGE/sK0uIFejhF0/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106559395346034450" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/Rt4ktuAIrxI/AAAAAAAAAGE/sK0uIFejhF0/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Step 3: Move the sprite to the position of the mouse&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now comes the part where we move our sprite.&lt;br /&gt;&lt;br /&gt;In order to move our sprite to the position of the mouse, we need to access the X and Y-positions of the mouse, and then change the position of the sprite to those positions. Place this code inside the if statement that checks if the left button of the mouse is pressed.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;spritePosition2.X = myMouse.X;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;spritePosition2.Y = myMouse.Y;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code is very simple and straightforward. All we are doing is resetting the X and Y-Positions of the sprite to the X and Y-Positions of the mouse, which we get by using the commands &lt;em&gt;mouseStateVariable.X&lt;/em&gt; and &lt;em&gt;mouseStateVariable.Y&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/Rt4mieAIr2I/AAAAAAAAAGs/EiooU5zxOf4/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106561401095761762" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/Rt4mieAIr2I/AAAAAAAAAGs/EiooU5zxOf4/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-3 The Code That Checks for Mouse Input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now there is just one problem left. By default, the mouse is not visible when it is on top of the screen. In order to fix this, place this code inside the &lt;em&gt;Initialize&lt;/em&gt; method above the &lt;em&gt;base.Initialize&lt;/em&gt; call.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;IsMouseVisible = &lt;span style="color:#3333ff;"&gt;true&lt;/span&gt;; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code just sets the mouse to be visible when it is on top of the screen.&lt;br /&gt;&lt;br /&gt;Now you have checked for mouse input, which is not that different from keyboard input. If you run the project now, you can move the second sprite to the position of the mouse whenever you press the left button of the mouse. Notice the sprite will move even when the mouse button has not been released yet. This is because we are not checking if the mouse has been clicked. We will solve this problem in a following tutorial.&lt;br /&gt;&lt;br /&gt;Finally, you may notice that if you click outside the screen, the sprite goes out of the screen also. We do not want this to happen. There are two ways we could come about stopping this. Either we could move the sprite to the edge of the screen when the mouse is clicked outside of the screen, or we could ignore mouse input when the mouse is clicked outside of the screen. I am going to choose the second option because it is easier.&lt;br /&gt;&lt;br /&gt;In order to ignore mouse input when the mouse is around the screen, after we have checked if the mouse is clicked, we need to check that the mouse is in the screen before we move the sprite. To do this, we can use an easy helper Microsoft has given us called Intellisense. Highlight the code that moves the sprite to the mouse position and right click.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/Rt4kt-AIryI/AAAAAAAAAGM/DSEIds80Oj8/s1600-h/ScreenShot4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106559399641001762" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/Rt4kt-AIryI/AAAAAAAAAGM/DSEIds80Oj8/s400/ScreenShot4.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-4 Intellisense Helping us Create an If Statement&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You should see a box come up. Click on &lt;em&gt;Surround with&lt;/em&gt; and then find the &lt;em&gt;if&lt;/em&gt;(or type in &lt;em&gt;i&lt;/em&gt;). Now hit enter. You should see that your code that moves the sprite is now surrounded with another if statement. Fill in the if statement as this if statement looks:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(mouse.X&lt;span style="font-size:78%;"&gt; &lt;span style="font-size:100%;color:#ff0000;"&gt;st&lt;/span&gt; &lt;/span&gt;screenRectangle.Right &amp;&amp;amp; mouse.X &gt; screenRectangle.Left &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;&amp;&amp;amp; mouse.Y &gt; screenRectangle.Bottom &amp;&amp;amp; mouse.Y &lt;span style="color:#ff0000;"&gt;st&lt;/span&gt; screenRectangle.Top&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;       spritePosition2.X = myMouse.X;&lt;br /&gt;       spritePosition2.Y = myMouse.Y;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This checks if the mouse is inside the screen rectangle by checking that the mouse positions are not outside of the screen rectangle edges.&lt;br /&gt;&lt;br /&gt;There is actually an easier way to do this though. We can just check if the mouse is inside of the rectangle by creating a rectangle around the mouse and then checking if it is inside of the screen rectangle by using a helper method that the rectangle class has called, &lt;em&gt;Intersects&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;Create a rectangle around the mouse by putting this code above the second if statement:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt; mouseRectangle = &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt;(myMouse.X, myMouse.Y, 1, 1);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This just creates a 1 by 1 pixel rectangle around the mouse. Now replace the code inside the second if statement with this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(mouseRectangle.Intersects(screenRectangle))&lt;br /&gt;{&lt;br /&gt;       spritePosition2.X = myMouse.X;&lt;br /&gt;       spritePosition2.Y = myMouse.Y;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;We are now checking of the mouse rectangle is intersecting the screen rectangle. If the mouse is outside of the screen, this if statement will not return true and the code inside will not be executed. &lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/Rt4kt-AIrzI/AAAAAAAAAGU/-iJBdzhhi4U/s1600-h/ScreenShot5.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106559399641001778" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/Rt4kt-AIrzI/AAAAAAAAAGU/-iJBdzhhi4U/s400/ScreenShot5.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-5 The New Code to Move the Sprite&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now you can move the sprite to where the mouse is clicked, but only if the mouse is inside of the screen.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/Rt4kxOAIr0I/AAAAAAAAAGc/dy2A351XmRI/s1600-h/ScreenShot6.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5106559455475576642" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/Rt4kxOAIr0I/AAAAAAAAAGc/dy2A351XmRI/s400/ScreenShot6.jpg" border="0" /&gt; &lt;p align="left"&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-6 Final Ouput of the Tutorial&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you have any requests or questions, please post a comment.&lt;br /&gt;&lt;br /&gt;Thanks for reading this tutorial.&lt;br /&gt;&lt;br /&gt;If something bad happens, do you really think that God does &lt;strong&gt;not &lt;/strong&gt;have it under control?&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-7214849789729978819?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/7214849789729978819/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=7214849789729978819' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7214849789729978819'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/7214849789729978819'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/mouse-input.html' title='Mouse Input'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_kLtxSdyLIgE/Rt4lsuAIr1I/AAAAAAAAAGk/Jl_0Cjxsjtk/s72-c/ScreenShot2.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-3563591881927647251</id><published>2007-09-02T16:50:00.000-07:00</published><updated>2007-09-08T17:45:04.161-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 5 -- Handling Input</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial teaches you how to move the sprite whenever a keyboard key is down.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A drawn, movable sprite (shown in Tutorial 4)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;View the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/handling-input.html"&gt;Tutorial 5&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Seriously, where do you think you are going to go when you die?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-3563591881927647251?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/3563591881927647251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=3563591881927647251' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3563591881927647251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/3563591881927647251'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-5-handling-input.html' title='Tutorial 5 -- Handling Input'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-4972509276755968166</id><published>2007-09-02T15:39:00.001-07:00</published><updated>2007-09-02T16:50:46.042-07:00</updated><title type='text'>Handling Input</title><content type='html'>&lt;span style="color:#ff0000;"&gt;&lt;strong&gt;Important Note:&lt;/strong&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt; When you see a red &lt;span style="color:#ff0000;"&gt;st&lt;/span&gt; inside a code sample, this means a "&lt;" symbol. Because of html tags and such with the website it won't let me draw the smaller than symbol.&lt;br /&gt;&lt;br /&gt;In this tutorial, you will learn how to move the sprite we have, based on input. Handling input is actually not that hard, thanks to the classes that Microsoft lets us use. In order to complete this tutorial, there are a few steps we need to do.&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Step 1 : Create a variable that can keep track of the keyboard input.&lt;br /&gt;Step 2 : Check for input constantly.&lt;br /&gt;Step 3 : Act upon input.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now let's do these steps.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1 : Create a variable that can keep track of the keyboard input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In order to check for input, we need to create a variable that can keep track of input. Microsoft has created a class that helps with this type of thing. This class is called a KeyboardState. Create a variable for this in the fields area:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;KeyboardState&lt;/span&gt; myKeyboard; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This creates a KeyboardState variable. Notice we don’t initialize it. That is because we will re-set the value of it every update, so we don’t need to spend time initializing it now.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; We didn’t put the private keyword in front of our variable declaration. This is because we don’t need to. If we don’t put private in front of the variable declaration, then the variable will become private by default.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2 : Check for input constantly&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is the step where we will actually check for input. Since we must always be checking for input(because the user can push a key at any time), we need to put our input checks in the &lt;em&gt;Update&lt;/em&gt; method. Again we will use if statements to check for input. Place this code inside the &lt;em&gt;Update&lt;/em&gt; method after the code you had placed there in the previous tutorials:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myKeyboard.IsKeyDown(&lt;span style="color:#66cccc;"&gt;Keys&lt;/span&gt;.Right))&lt;br /&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myKeyboard.IsKeyDown(&lt;span style="color:#66cccc;"&gt;Keys&lt;/span&gt;.Left))&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code actually checks for input. We have put two different checks to check if the left or right arrow keys have been pressed. You can probably see what is going on in these if statements.&lt;br /&gt;&lt;br /&gt;First off, we access the &lt;em&gt;IsKeyDown&lt;/em&gt; method of our keyboard variable &lt;em&gt;myKeyboard&lt;/em&gt;. This method checks if a key was is currently held down. We want to see if the right or left arrows of the keyboard is down so we pass in as parameters, &lt;em&gt;Keys.Right&lt;/em&gt; or &lt;em&gt;Keys.Left&lt;/em&gt;. Keys is a class Microsoft has let us use that stores all the keys on the keyboard.&lt;br /&gt;&lt;br /&gt;Now that we have the input checks done, there is one thing we have to do before we can actually put something inside these if statements. We need to actually get the current state of the keyboard. To do this, put this code at the top of the &lt;em&gt;Update&lt;/em&gt; method, underneath the code to exit the game:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;myKeyboard = &lt;span style="color:#66cccc;"&gt;Keyboard&lt;/span&gt;.GetState();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As I was saying earlier, we didn’t initialize &lt;em&gt;myKeyboard&lt;/em&gt; because we would reset it’s value every update. In this line of code, we are setting &lt;em&gt;myKeyboard&lt;/em&gt; to a value of the current state of the keyboard. We get the current state of the keyboard by using the command &lt;em&gt;Keyboard.GetState()&lt;/em&gt; which calls the &lt;em&gt;GetState&lt;/em&gt; method of the Keyboard class. The &lt;em&gt;GetState&lt;/em&gt; method takes no parameters.&lt;br /&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrpI/AAAAAAAAAFE/v_K0w5yxZAw/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756026008284818" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrpI/AAAAAAAAAFE/v_K0w5yxZAw/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-1 Initializing Our Keyboard Variable Every Update&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 3 : Act upon input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This is the final step, and the step where we actually get to do move our sprite based upon the keyboard input. We want our sprite to move only when we push the arrow keys. Instead of constantly updating the sprite’s position like we have been doing, we will now only move the sprite if an arrow key is pressed. Delete the code that increases the sprite’s position by &lt;em&gt;speed&lt;/em&gt; and place this code inside the if statements that check for input.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#009900;"&gt;//This code inside the right arrow input check&lt;br /&gt;&lt;/span&gt;spritePosition.X += speed;&lt;br /&gt;&lt;span style="color:#009900;"&gt;//This code inside the left arrow input check&lt;/span&gt;&lt;br /&gt;spritePosition.X -= speed; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code will move the sprite only when the left or right arrows of the keyboard have been pushed. We increase the sprite’s X-position by speed when the right arrow is down, and decrease the sprite’s X-position by speed when the left arrow is down.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrqI/AAAAAAAAAFM/aD26PtYCrmg/s1600-h/ScreenShot2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756026008284834" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrqI/AAAAAAAAAFM/aD26PtYCrmg/s400/ScreenShot2.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-2 Moving Our Sprite Based on Keyboard Input&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now since we won’t need the sprite to reverse direction when it collides with the side of the screen, you can replace the old collision code with this new code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Right &gt; screenRectangle.Right)&lt;br /&gt;{&lt;br /&gt;     spritePosition.X = screenRectangle.Right - myTexture.Width;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Left &lt;span style="color:#ff0000;"&gt;st&lt;/span&gt; screenRectangle.Left)&lt;br /&gt;{&lt;br /&gt;     spritePosition.X = screenRectangle.Left;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;All this code does is, if the sprite’s left or right side has started to go beyond the screen. Then the sprite’s left or right side will be set to the left or right side of the screen. This way the sprite cannot go beyond the edges of the screen.&lt;br /&gt;&lt;br /&gt;You may think it would be easier to type &lt;em&gt;spriteCollisionRectangle.Right = screenRectangle.Right&lt;/em&gt; or &lt;em&gt;spriteCollisionRectangle.Left = screenRectangle.Left&lt;/em&gt;. This would be easier but there are two problems that occur with this.&lt;br /&gt;&lt;br /&gt;First of all, if you wrote that, the compiler would throw an error because for some reason you cannot change the values of the rectangle, you can only use them. In other words, the rectangle values are readonly(a C# keyword).&lt;br /&gt;&lt;br /&gt;Second of all, even if you could change the values of the rectangle, why would you want to. If all we did was move the collision rectangle, the position of the sprite would stay the same. In other words, if we just moved the sprite's collision rectangle, the sprite would not stop moving because his position is not being changed, only his collision rectangle.&lt;br /&gt;&lt;br /&gt;In order to make it where the position of the sprite is changed, we have to access either the sprite's X or Y-positions. Since we are moving horizontaly we accesss the sprite's X-position.&lt;br /&gt;&lt;br /&gt;Then we need to stop the sprite's X-position movement when we are colliding with the screen edge.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrrI/AAAAAAAAAFU/gLlQuViAlgY/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756026008284850" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrrI/AAAAAAAAAFU/gLlQuViAlgY/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-3 The New Collision Code&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We put &lt;em&gt;spritePosition.X = screenRectangle.Right - myTexture.Width&lt;/em&gt;. All this code is doing is setting the X-position of the sprite to the right side of the screen. We need to minus the width of the texture because the X-position of the sprite refers to the left side of the sprite and since we want to make it seem like there is a collision with the right side of the sprite and the right side of the screen, we need to actually make a collision with the left side of the sprite(the sprite's X-position), and the right side of the screen minus the width of the texture.&lt;br /&gt;&lt;br /&gt;When we do the command &lt;em&gt;spritePosition.X = screenRectangle.Left&lt;/em&gt; we don't have to make any changes because we are setting the left side of the sprite to the left side of the screen.&lt;br /&gt;&lt;br /&gt;Now test your project. You should be able to move the sprite based on keyboard input. Also, the sprite should stop when it collides with the sides of the screen.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RttKDuAIrsI/AAAAAAAAAFc/XfMQfyaeI5E/s1600-h/ScreenShot4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756030303252162" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RttKDuAIrsI/AAAAAAAAAFc/XfMQfyaeI5E/s400/ScreenShot4.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-4 The final result&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Just to add a little more functionality into our project, add this code into the &lt;em&gt;Update&lt;/em&gt; method to allow up and down movement:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;color:#009900;"&gt;//Under the left and right arrow input checks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myKeyboard.IsKeyDown(Keys.Down))&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     spritePosition.Y += speed;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(myKeyboard.IsKeyDown(Keys.Up))&lt;br /&gt;{&lt;br /&gt;     spritePosition.Y -= speed;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;color:#009900;"&gt;//Under the left and right side collision checks&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Bottom &gt; screenRectangle.Bottom)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;     spritePosition.Y = screenRectangle.Bottom - myTexture.Height;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Top &lt;span style="color:#ff0000;"&gt;st&lt;/span&gt; screenRectangle.Top)&lt;br /&gt;{&lt;br /&gt;     spritePosition.Y = screenRectangle.Top;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Finally, move all the collision code underneath the input code. I don't know why but I like to have input code before collision code.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RttKDuAIrtI/AAAAAAAAAFk/rgkt_0eDu6g/s1600-h/ScreenShot5.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756030303252178" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RttKDuAIrtI/AAAAAAAAAFk/rgkt_0eDu6g/s400/ScreenShot5.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-5 The New Update Method With Added Code&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now you can move your sprite up and down also. You should be able to understand what this code does.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RttKG-AIruI/AAAAAAAAAFs/zNDDrsQeDJc/s1600-h/ScreenShot6.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105756086137827042" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RttKG-AIruI/AAAAAAAAAFs/zNDDrsQeDJc/s400/ScreenShot6.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-6 The Final, Final Result&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you have any requests or if parts of this tutorial were confusing, please post a comment.&lt;br /&gt;&lt;br /&gt;Thanks for reading this tutorial.&lt;br /&gt;&lt;br /&gt;Seriously, what do you think will happen to you when you die? &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-4972509276755968166?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/4972509276755968166/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=4972509276755968166' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4972509276755968166'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/4972509276755968166'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/handling-input.html' title='Handling Input'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp2.blogger.com/_kLtxSdyLIgE/RttKDeAIrpI/AAAAAAAAAFE/v_K0w5yxZAw/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-202939532091269307</id><published>2007-09-01T16:32:00.000-07:00</published><updated>2007-09-08T17:45:04.162-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 4 -- Rectangle Collisions</title><content type='html'>&lt;strong&gt;Introduction &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial shows how to do some collision checking using the Rectangle class. You will end up with a sprite moving from one side of the screen to the next reversing its direction whenever it collides with a screen edge.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;A moving sprite (shown in tutorial 3)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;View the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/rectangle-collisions.html"&gt;Tutorial 4&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;You don't have to live a life with no point. God offers a free gift. Take it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-202939532091269307?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/202939532091269307/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=202939532091269307' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/202939532091269307'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/202939532091269307'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-4-rectangle-collisions.html' title='Tutorial 4 -- Rectangle Collisions'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-427338355204439675</id><published>2007-09-01T15:43:00.000-07:00</published><updated>2007-09-01T16:32:09.972-07:00</updated><title type='text'>Rectangle Collisions</title><content type='html'>&lt;div align="left"&gt;&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;Very Important Note:&lt;/span&gt;&lt;/strong&gt; You will see a red &lt;span style="color:#ff0000;"&gt;st &lt;/span&gt;&lt;span style="color:#000000;"&gt;in one of the if statements below. This stands for a smaller than sign "&lt;". Make sure to put that instead. I had to put st because the web site uses html and it thinks I am trying to create a tag using html. &lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;strong&gt;Note:&lt;/strong&gt; All words in italics are names of things.&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;In this tutorial you will learn the basics of collision handling. What we want to accomplish in this tutorial is to make our sprite reverse directions when it hit’s either side of the screen. In order to accomplish this we need to create some kind of collision box around the sprite every time the game updates. Then we can check for a collision with the side of the screen and reverse the sprite’s direction accordingly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In order to accomplish this there are a few steps we need to do:&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;Step 1 : Every update(every time the game calls the Update method) create a collision box around the sprite.&lt;br /&gt;Step 2 : Check for collisions with the sprite and the screen.&lt;br /&gt;Step 3 : Reverse the sprites direction if there is a collision.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Once we accomplish these steps we will hopefully have a sprite colliding with the screen borders.&lt;br /&gt;&lt;strong&gt;Step 1 : Every update create a collision box around the sprite&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;First of all, we need to create a collision box around the sprite. Microsoft has provided us with a class that helps with this type of stuff. This class is called Rectangle. In order to create a rectangle that we can use for collision checking, we could do one of two things.&lt;br /&gt;&lt;br /&gt;One idea is to create a rectangle around the sprite when we first start the game, and then every time the sprite moves, update the position of this rectangle.&lt;br /&gt;&lt;br /&gt;Another idea is to only create a rectangle around the sprite when we are going to start collision checking That way, the rectangle is already at the current position of the sprite. I am going to use this method because that way I don’t have to worry about updating the position of the collision rectangle.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now that we have decided what we are going to do, we can actually do it. Since we want to create the rectangle at the time we are going to check for collisions(every loop), we are going to put this code inside the &lt;em&gt;Update&lt;/em&gt; method. Put this code before the call to move the sprite, but after the call to create &lt;em&gt;speed&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt; spriteCollisionRectangle = &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt;((&lt;span style="color:#3333ff;"&gt;int&lt;/span&gt;)spritePosition.X, (&lt;span style="color:#3333ff;"&gt;int&lt;/span&gt;)spritePosition.Y, myTexture.Width, myTexture.Height);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code creates our rectangle around the sprite. First of all, we create a rectangle variable. Then we initialize the variable. You can see that we are calling the constructor of the rectangle class. This constructor needs two positions to create the rectangle at, and then the width and height the rectangle should be. In order to make a rectangle boxing in our sprite, we pass in the position of the sprite(the X and Y-coordinates), and then we pass in the width and height of the texture we are using. We get this by using the commands &lt;em&gt;myTexture.Width&lt;/em&gt; and &lt;em&gt;myTexture.Height&lt;/em&gt;. Notice we put &lt;em&gt;(int)&lt;/em&gt; in front of the sprite positions. This is because the sprite positions(&lt;em&gt;spritePosition.X and spritePosition.Y&lt;/em&gt;) when we try to use them return(give a value of) a float. The rectangle constructor only takes integers as it’s parameters so we have to convert the float into an integer(int). This is a process know as casting.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we have created our collision rectangle around our sprite. Every update loop this rectangle is re-created to be at the current position of the sprite.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RtnxTuAIriI/AAAAAAAAAEM/WixTIaLHUw0/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105376973669576226" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RtnxTuAIriI/AAAAAAAAAEM/WixTIaLHUw0/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-1 The Creation of the Sprite’s Collision Rectangle&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2 : Check for collisions with the sprite and the screen&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;Now that we have a rectangle for our sprite, we can start to check for collisions. First lets make a variable to hold the rectangle for the screen. Put this code under your code for the sprite’s rectangle:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt; screenRectangle = &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Rectangle&lt;/span&gt;(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code creates a rectangle for our screen. First we put, &lt;em&gt;0, 0&lt;/em&gt;, which is always the position that the top left corner of the screen is at. Then we pass in the width and height of the screen by using the commands &lt;em&gt;graphics.GraphicsDevice.Viewport.Width&lt;/em&gt; or &lt;em&gt;graphics.GraphicsDevice.Viewport.Height&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;Now that we have our screen rectangle created, it is time to check for collisions.&lt;br /&gt;&lt;br /&gt;All we have to do to check for a collision is add an if statement. In order to check for a collision with the right side of the screen and the right side of the sprite, add this code underneath the rectangle variable declarations:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Right &gt; screenRectangle.Right)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;This code is your first if statement. First we place the word &lt;em&gt;if&lt;/em&gt;. Then we place two parentheses after the &lt;em&gt;if&lt;/em&gt;. Then inside of the two parentheses we write what we are checking for. We want to see if the right side of the sprite rectangle is at a greater position than the right side of the screen rectangle. We do this by accessing the right side position of these rectangles(&lt;em&gt;rectangleName.Right&lt;/em&gt;), and checking their positions by using the &gt; operator which checks if one value is greater than another.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note :&lt;/strong&gt; Using the command, &lt;em&gt;rectangleName.Right&lt;/em&gt;, just gets the position of the right side of the rectangle.&lt;br /&gt;&lt;br /&gt;After the if and the two parentheses, we just add two curly brackets. These brackets are where you would put any code that you want to be executed if the &lt;em&gt;spriteCollisionRectangle&lt;/em&gt;’s right side is greater than the &lt;em&gt;screenRectangle&lt;/em&gt;’s right side. We will fill these brackets in the next step. For now, lets just finish up checking for collisions.&lt;br /&gt;Add this code to check for collisions with the left side of the screen and the left position of the sprite’s rectangle:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;if&lt;/span&gt;(spriteCollisionRectangle.Left &lt;span style="color:#ff0000;"&gt;st&lt;/span&gt; screenRectangle.Left)&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt; &lt;/div&gt;&lt;div align="left"&gt;&lt;span style="font-family:courier new;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Notice that we have changed the &gt; to a &lt;. This is because we are checking for a collision with the left side of the screen. And since when you are moving left, your position is getting smaller so you need to put &lt;. &lt;strong&gt;Note :&lt;/strong&gt; If you put &gt;= or &lt;= the project will not work because then we are checking if the sprite rectangle’s side is greater or equal to the side of the screen and since we start out at position 0, 0, there is a collision from the start. In the end the sprite will end up not moving at all. If you really want to know why then post a comment. &lt;/div&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrjI/AAAAAAAAAEU/KWenDqQAn3Q/s1600-h/ScreenShot2.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105376977964543538" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrjI/AAAAAAAAAEU/KWenDqQAn3Q/s400/ScreenShot2.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-2 The Screen Rectangle and If Statements&lt;/strong&gt; &lt;div align="left"&gt;&lt;br /&gt;&lt;strong&gt;Step 3 : Reverse the sprites direction if there is a collision&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now that we have all the collision if statements down, all there is left to do is make those if statements change something. All we have to do is reverse the direction that the sprite is moving in. Place this code inside both sets of brackets following the if statements:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;speed = -speed;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code changes the speed that the sprite is moving by, to its opposite. Since the sprite’s X-position is being increased by &lt;em&gt;speed&lt;/em&gt;, if &lt;em&gt;speed&lt;/em&gt; equals 0.5(the sprite is moving right) then &lt;em&gt;speed&lt;/em&gt; will be reversed to -0.5 which means the sprite’s position will be increased by -0.5 or in simpler words subtracted by 0.5(moving left).&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrkI/AAAAAAAAAEc/CCGhsncFO3Q/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105376977964543554" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrkI/AAAAAAAAAEc/CCGhsncFO3Q/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-3 The Code in the If Statements that Reverses the Sprite’s Direction&lt;/strong&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;br /&gt;Now there is just one thing to fix. We need to stop recreating &lt;em&gt;speed &lt;/em&gt;each time the &lt;em&gt;Update&lt;/em&gt; method is called. This is because when we recreate &lt;em&gt;speed&lt;/em&gt;, we are resetting its value to 0.5 which means that if none of the if statements return(end up as) true(say the sprite is in the middle of the screen so there are no collisions happening), then even if the sprite was moving left, the sprite would move right because when we recreate &lt;em&gt;speed&lt;/em&gt; we are setting or more often re-setting it’s value to 0.5 which means moving right.&lt;br /&gt;&lt;br /&gt;All we need to do to change this is move the creation of &lt;em&gt;speed&lt;/em&gt; to the fields area. This will give &lt;em&gt;speed&lt;/em&gt; an initial value of 0.5(moving right) but if we reverse the value of &lt;em&gt;speed&lt;/em&gt; in an if statement, &lt;em&gt;speed&lt;/em&gt; will keep that new value instead of constantly being reset to 0.5.&lt;br /&gt;&lt;br /&gt;Move the, &lt;em&gt;float speed = 0.5&lt;/em&gt;, in the &lt;em&gt;Update&lt;/em&gt; method, up to where we placed our fields.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;p align="left"&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrlI/AAAAAAAAAEk/3sw7z1FmSd4/s1600-h/ScreenShot4.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105376977964543570" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RtnxT-AIrlI/AAAAAAAAAEk/3sw7z1FmSd4/s400/ScreenShot4.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-4 Moving Speed Up To Our Fields Area&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now if you test the project, the sprite will reverse it’s direction when it collides with the sides of the screen. You have now learned how to do some basic collision checking.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RtnxUOAIrmI/AAAAAAAAAEs/5AlbO7Fu5Wo/s1600-h/ScreenShot5.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105376982259510882" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RtnxUOAIrmI/AAAAAAAAAEs/5AlbO7Fu5Wo/s400/ScreenShot5.jpg" border="0" /&gt;&lt;/a&gt; &lt;strong&gt;Figure 1-5 Finished Tutorial - The Sprite Just Bounced Off of the Right Side of the Screen&lt;/strong&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Finally, just change the initial value of &lt;em&gt;speed&lt;/em&gt; to 5 so that we can get the sprite moving a bit faster:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/Rtnxb-AIrnI/AAAAAAAAAE0/avmoeOK7tY4/s1600-h/ScreenShot6.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105377115403497074" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/Rtnxb-AIrnI/AAAAAAAAAE0/avmoeOK7tY4/s400/ScreenShot6.jpg" border="0" /&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-6 Changing Speed to the Value of 5&lt;/strong&gt; &lt;/p&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div align="left"&gt;If you have any requests or if parts of this tutorial were confusing post a comment.&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;Thanks for reading this tutorial.&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div align="left"&gt;You don’t need to live a life that has no point. God is offering you a free gift. Take it.&lt;/div&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-427338355204439675?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/427338355204439675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=427338355204439675' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/427338355204439675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/427338355204439675'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/rectangle-collisions.html' title='Rectangle Collisions'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_kLtxSdyLIgE/RtnxTuAIriI/AAAAAAAAAEM/WixTIaLHUw0/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-8203399044077509223</id><published>2007-09-01T15:27:00.000-07:00</published><updated>2007-09-08T17:45:04.162-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 3 -- Moving Our Sprite</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial explains how to move a sprite. There is no collision checking or input handling. This tutorial is meant to teach someone how to move a sprite.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A sprite drawn on the screen (shown in Tutorial 2).&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;View the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/09/moving-our-sprite.html"&gt;Tutorial 3&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Don't worry. God has everything under control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-8203399044077509223?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/8203399044077509223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=8203399044077509223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8203399044077509223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8203399044077509223'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/tutorial-3-moving-our-sprite.html' title='Tutorial 3 -- Moving Our Sprite'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6702493641893613345</id><published>2007-09-01T14:12:00.000-07:00</published><updated>2007-09-01T15:26:51.499-07:00</updated><title type='text'>Moving Our Sprite</title><content type='html'>&lt;div align="left"&gt;&lt;strong&gt;Note: Words in italic are names of things.&lt;/strong&gt;&lt;strong&gt;&lt;br /&gt;&lt;/div&gt;&lt;p align="left"&gt;&lt;/strong&gt;Now that you have a pretty sweet sprite drawn on the screen. It is time to actually make the sprite do something. Here are the steps we need to do to make the sprite move: &lt;/p&gt;&lt;p align="left"&gt;&lt;strong&gt;Step 1 : Give our sprite a position variable so that we can change the sprite’s position.&lt;br /&gt;Step 2 : Draw the sprite at the position variable instead of at a variable we create when we call mySpriteBatch to draw.&lt;br /&gt;Step 3 : Every time the computer loops through the code, move the sprite by a certain amount. &lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;These steps we will accomplish and hopefully, without much confusion.&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;p align="left"&gt;&lt;strong&gt;Step 1 -- Give our sprite a position variable so that we can change the sprite’s position&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;As the name of this step shows, we need to create a variable for our sprite. You may be wondering why we need to do this because we already created a variable for the position of the sprite in the call to draw: &lt;/p&gt;&lt;div align="center"&gt;&lt;/div&gt;&lt;img id="BLOGGER_PHOTO_ID_5105362744442924498" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtnkXeAIrdI/AAAAAAAAADk/TYPcQT7tRVg/s400/ScreenShot1.jpg" border="0" /&gt; &lt;p align="center"&gt; &lt;strong&gt;Figure 1-1 The Call to Draw the Sprite at a Position &lt;/strong&gt;&lt;/p&gt;&lt;strong&gt;&lt;p align="left"&gt;&lt;/strong&gt;Well, yea, we created this variable but there is a problem:&lt;br /&gt;This variable does not have a name that we can access it by. When we call &lt;em&gt;mySpriteBatch&lt;/em&gt; to draw, we are creating a new Vector2 class to draw the sprite at. This is useful if you are never going to need to access this variable, but throws a problem when we want to change the value of this variable. In order to fix this problem, we need to create a Vector2 variable that can be accessed from everywhere inside the class. Then we can always change this position whenever we want to.&lt;br /&gt;To create this variable, type this code in the fields area(the place where all our other variable declarations are):&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt; spritePosition;&lt;/span&gt;&lt;/p&gt;&lt;p align="left"&gt;This code creates our Vector2 variable that can hold the position of our sprite. Now we need to initialize it.&lt;br /&gt;Instead of going to the &lt;em&gt;Initialize&lt;/em&gt; method, we can just initialize the variable at the same time that we create it. To do this, replace the code you just typed, with the following:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt; spritePosition = &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;(0, 0);&lt;/span&gt;&lt;/p&gt;Now we have created our variable, and initialized it at the same time. It is easier to do this instead of creating the variable and then initializing it somewhere else. The reason we didn’t initialize &lt;em&gt;mySpriteBatch&lt;/em&gt; when we first created it was because in order to initialize the &lt;em&gt;mySpriteBatch&lt;/em&gt;, we had to use the GraphicsDeviceManager variable &lt;em&gt;graphics&lt;/em&gt;. It happens that &lt;em&gt;graphics&lt;/em&gt; is not initialized until the constructor is called. If I try to use &lt;em&gt;graphics&lt;/em&gt; to initialize &lt;em&gt;mySpriteBatch&lt;/em&gt; before it is initialized, the compiler(program that processes the code) will throw and error because the GraphicsDevice inside of &lt;em&gt;graphics&lt;/em&gt; is set to null.&lt;br /&gt;&lt;br /&gt;If that was confusing just think of it as I need &lt;em&gt;graphics&lt;/em&gt; to be set to a value before I can use it, and since &lt;em&gt;graphic&lt;/em&gt;s is not set to a value until the constructor is called, I need to create &lt;em&gt;mySpriteBatc&lt;/em&gt;h after the constructor is called, which is in the &lt;em&gt;Initialize&lt;/em&gt; method.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2 -- Draw the sprite at the position variable instead of at a variable we create when we call mySpriteBatch to draw&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now that we have an initialized Vector2 variable to work with, lets test out the variable by changing the call to draw. Replace the old &lt;em&gt;mySpriteBatch.Draw&lt;/em&gt; call with this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Draw(myTexture, spritePosition, &lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code replaces the, new Vector2(0, 0), call we had there earlier, with our Vector2 variable &lt;em&gt;spritePosition&lt;/em&gt;. This does not throw an error because all the &lt;em&gt;Draw&lt;/em&gt; method is asking for is a Vector2, so whether we pass in a new Vector2 we create at the moment, or a variable, it doesn’t matter because all that the method needs is a Vector2.&lt;br /&gt;&lt;br /&gt;If you run the project right now, you should see the same sprite placed at the exact same position it was at the end of the last tutorial. This is because we didn’t change the value of &lt;em&gt;spritePosition&lt;/em&gt;. We kept the &lt;em&gt;spritePosition&lt;/em&gt; at the value of 0, 0, which was the same value of the new Vector2 we had created when we called to draw. Build the project anyway, just to make sure everything is working correctly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5105362744442924514" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtnkXeAIreI/AAAAAAAAADs/inXwqUeCPTY/s400/ScreenShot2.jpg" border="0" /&gt; &lt;p align="center"&gt;&lt;strong&gt;Figure 1-2 Your Output Should Look Like This&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;strong&gt;Step 3 : Every time the computer loops through the code, move the sprite by a certain amount&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;Now comes the fun part. Actually moving the sprite. &lt;/p&gt;&lt;p align="left"&gt;Since we put the position of a sprite in a variable. All we need to do to move the sprite is change it’s position by a certain amount every time the compiler loops through the code. To make this happen, we need to go to the &lt;em&gt;Update&lt;/em&gt; method. The &lt;em&gt;Update&lt;/em&gt; method is called every time the compiler loops and is where you want to place all your game code. By this I mean all code that updates positions, collision handling, input checking, etc… You do not want to put draw code in this method though. You should put drawing code inside of the &lt;em&gt;Draw&lt;/em&gt; method.&lt;br /&gt;Once you have located the &lt;em&gt;Update&lt;/em&gt; method, place this code inside of it. I put my code in between the input check for exiting the game, and the &lt;em&gt;base.Draw(gameTime)&lt;/em&gt;, call. &lt;/p&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;float&lt;/span&gt; speed = 0.5f;&lt;br /&gt;spritePosition.X += speed;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code moves our sprite by a certain amount every time the compiler loops through the code.&lt;br /&gt;First we create a variable to keep the speed the sprite should move at. We store this variable as a float, which is like a decimal, but it only keeps the first 7 decimal points. We set the value of the speed to 0.5f. We put an f or an F after the number to show that this number is a float. If you don’t put it there, the compiler will think that you are trying to make an integer and since integers can't hold numbers after the decimal point, the compiler will throw an error.&lt;br /&gt;&lt;br /&gt;After we declare &lt;em&gt;speed&lt;/em&gt;, we need to change the sprite’s position. We want to move the sprite to the right so we have to do two things.&lt;br /&gt;&lt;br /&gt;First we have to access the X-coordinate of &lt;em&gt;spritePosition&lt;/em&gt; because we want to move the position of the sprite sideways.&lt;br /&gt;&lt;br /&gt;Secondly, we have to add to the X-coordinate of the sprite. We add because we want to move the sprite to the right. The further right to the screen(in a 2D game) means the higher the number of the X-coordinate. The further left to the screen means the lower the number.&lt;br /&gt;&lt;br /&gt;Now maybe you have just one more question. What does the += operator mean?&lt;br /&gt;Putting the += operator is the same thing as putting: &lt;em&gt;spritePosition.X = spritePositon.X + speed;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/RtnlU-AIrhI/AAAAAAAAAEE/866rBGDhxjs/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105363801004879378" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/RtnlU-AIrhI/AAAAAAAAAEE/866rBGDhxjs/s400/ScreenShot3.jpg" border="0" /&gt; &lt;p align="center"&gt;&lt;/a&gt;&lt;strong&gt;Figure 1-3 The code in the Update Method&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;Now if you run the project. The sprite should move across the screen at a slow pace. If you are patient enough to watch though, we have one problem. The sprite doesn’t stop when it hit’s the end of the screen. Even though we could fix that problem now, I want to save that for the next tutorial. What we learned in this tutorial though, is how to move a sprite. Which, after all, only takes a few lines of code.&lt;br /&gt;&lt;br /&gt;You can run the code now and enjoy your sprite moving across the scene…until it moves off the screen.&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5105362748737891842" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RtnkXuAIrgI/AAAAAAAAAD8/ON4SR8FsDX0/s400/ScreenShot4.jpg" border="0" /&gt; &lt;p align="center"&gt;&lt;strong&gt;Figure 1-4 Our Finished Tutorial&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;strong&gt;P.S.&lt;/strong&gt; Try seeing how you can move the sprite’s Y-coordinate. I’m sure you can figure it out. Just one tip : The further towards the bottom of the screen, the higher the number of the Y-coordinate. Once you have tested the code enough, make sure to erase all modifications you made so we can all be on the same page for the next tutorial.&lt;br /&gt;&lt;br /&gt;If you have any questions or requests, post a comment for this tutorial.&lt;br /&gt;&lt;br /&gt;Thanks&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember:&lt;/strong&gt; Don’t worry, the Lord has everything under control.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6702493641893613345?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6702493641893613345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6702493641893613345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6702493641893613345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6702493641893613345'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/09/moving-our-sprite.html' title='Moving Our Sprite'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_kLtxSdyLIgE/RtnkXeAIrdI/AAAAAAAAADk/TYPcQT7tRVg/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-2692387817239561752</id><published>2007-08-31T16:43:00.000-07:00</published><updated>2007-09-01T11:54:23.040-07:00</updated><title type='text'>Drawing Our First Sprite</title><content type='html'>&lt;div align="left"&gt;In this tutorial, we will learn how to draw an image onto the screen. First of all I will tell you the steps needed in order to draw a sprite(2d image) onto the screen.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1 : Create a variable that is capable of holding a 2d texture image.&lt;br /&gt;Step 2 : Load the actual image that we are going to draw, into the project.&lt;br /&gt;Step 3 : Give the texture variable that we created the value of the actual image we loaded into the project.&lt;br /&gt;Step 4 : Draw the image onto the screen each frame.&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I will go through these steps, trying to make it as easy as possible.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;strong&gt;Note:&lt;/strong&gt; All words in Italics are names of some item or variable.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 1-Create a variable that is capable of holding a 2d texture image&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;p align="left"&gt;First off we need to create a variable that can hold all the information a texture image has. Thankfully, Microsoft has made XNA, which has lots of different classes that have different uses. Out of these classes is one that is perfect for our use. This class is called the Texture2D class. So now right above the constructor(&lt;em&gt;public Game1()&lt;/em&gt;) type in this code : &lt;/p&gt;&lt;p align="left"&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#00cccc;"&gt;Texture2D&lt;/span&gt; myTexture;&lt;/span&gt; &lt;/p&gt;&lt;p align="left"&gt;&lt;br /&gt;Simple enough. First off we declare &lt;em&gt;private&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;private&lt;/em&gt; is a keyword and should appear in blue. All that this word does is set an access modifier. In other words, by using this word in front of a variable declaration, we have said that only code inside the &lt;em&gt;Game1&lt;/em&gt; class can access it. &lt;/p&gt;&lt;br /&gt;&lt;div align="left"&gt;Next we have the &lt;em&gt;Texture2D&lt;/em&gt;.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;This is referring back to the class I told you about. This is a class that holds information about 2d texture images.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;p align="left"&gt;After the Texture2D statement, we have the &lt;em&gt;myTexture.&lt;/em&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;This should not appear in any special color, because this is just a name. This name refers to one Texture2D class. Now whenever we want to access something that a Texture2D class has, we just use &lt;em&gt;myTexture&lt;/em&gt;. I have named our Texture2D class, &lt;em&gt;myTexture&lt;/em&gt;, but it doesn’t really matter what you name it. Be careful though, names of variables &lt;strong&gt;are&lt;/strong&gt; case sensitive.&lt;br /&gt;&lt;/p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/Rtm06eAIrcI/AAAAAAAAADc/8zfi5ptRcjY/s1600-h/ScreenShot1.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105310569180212674" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/Rtm06eAIrcI/AAAAAAAAADc/8zfi5ptRcjY/s400/ScreenShot1.jpg" border="0" /&gt;&lt;/a&gt; &lt;p align="left"&gt;&lt;strong&gt;Figure 1-1 The Variable Declaration&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Last but not least, we end our variable name with a semicolon. Semicolons are used to end statements. There is a pretty basic rule about semi colons. Whenever a statement has two following curly braces after it, then you do not put a semicolon. Otherwise, pretty much always end statements with a semicolon.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Step 2-Load the actual image that we are going to draw, into the project&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;&lt;br /&gt;After we have created our variable and named it &lt;em&gt;myTexture&lt;/em&gt;. We can draw it right? Wrong. All the values inside &lt;em&gt;myTexture&lt;/em&gt;(our Texture2D class) are set to default and null(nothing) values. We can’t draw the image because some of the data is nothing. First we need to set our &lt;em&gt;myTexture&lt;/em&gt; variable to an image, and then we can draw it. Now the problem is how to do just that. How do we set a Texture2D variable to a real image? Theoretically, we could create a file stream and then load a texture image that way, but it would be way harder. Microsoft has again created an easier way to load content(images, sound, models, etc). This is called the Content Pipeline. All we have to do is load our image into our project, and then do a simple command to access this image.&lt;br /&gt;&lt;br /&gt;First, lets load our image into our project. Go to the Solution Explorer(View--&gt;Solution Explorer). Now you should see the name of your project with a little computer flag by it(that is the symbol for a Windows Game). Right click on the name of your project and go to Add--&gt; Existing Item. &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RtmuguAIrRI/AAAAAAAAACE/2qmFWUY7nMM/s1600-h/ScreenShot2.jpg"&gt;&lt;/p&gt;&lt;/a&gt;&lt;img id="BLOGGER_PHOTO_ID_5105303529728814354" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RtmuguAIrRI/AAAAAAAAACE/2qmFWUY7nMM/s400/ScreenShot2.jpg" border="0" /&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;Figure 1-2 Add-Existing Item&lt;/strong&gt;&lt;/div&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Now you should see your some files of your game. Browse to where the image you want to add is. You should see nothing. This is because you are not looking at files related to the Content Pipeline. Go to the bottom where the Files of Type drop down box is. Select Content Pipeline files. Now you should see your image. Select that image and click Add(bottom-right). In the Solution Explorer under the files related to your project, you should see your image file. Now you have added the image into your project. The next step is to do something with it.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/Rtmug-AIrSI/AAAAAAAAACM/aiK1VYJvJ1I/s1600-h/ScreenShot3.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105303534023781666" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/Rtmug-AIrSI/AAAAAAAAACM/aiK1VYJvJ1I/s400/ScreenShot3.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;Figure 1-3 Added Image&lt;/strong&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;strong&gt;Step 3 : Give the texture variable that we created the value of the actual image we loaded into the project&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;We are half way done now. We still can’t draw anything yet because our values in the &lt;em&gt;myTexture&lt;/em&gt; variable are still set to default and null values. Even though we loaded the image into our project. The &lt;em&gt;myTexture&lt;/em&gt; variable doesn’t just magically get assigned the value of the texture. In order to assign the &lt;em&gt;myTexture&lt;/em&gt; variable to the image we loaded into our project, we need to type this line of code inside the &lt;em&gt;LoadGraphicsContent&lt;/em&gt; method:&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5105304105254432082" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RtmvCOAIrVI/AAAAAAAAACk/BWCsmiwJ00c/s400/ScreenShot6.jpg" border="0" /&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;Figure 1-4 The LoadGraphicsContent Method&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;After you have located the method, you should see an if statement. Inside the if statement should be a green line of code(It is green because it is a comment. Comments are marked with two preceding backslashes and are just there to help the coder). Delete the comment and type in this line of code in it’s place: &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="font-family:courier new;"&gt;myTexture = content.Load&lt;&lt;span style="color:#00cccc;"&gt;Texture2D&lt;/span&gt;&lt;span style="color:#000000;"&gt;&gt;(&lt;/span&gt;&lt;span style="color:#cc0000;"&gt;“&lt;/span&gt;&lt;span style="color:#cc0000;"&gt;JesusRocks&lt;/span&gt;&lt;span style="color:#cc0000;"&gt;“&lt;/span&gt;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the actual code that loads our texture variable with a real image. Pretty sweet. One problem though. It may be kind of confusing. Hopefully not for long.&lt;br /&gt;First we start with &lt;em&gt;myTexture =&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;This is getting our &lt;em&gt;myTexture&lt;/em&gt; variable ready to be assigned(or re-assigned) a value. The equals operator(sign) is used like it shows in pretty much all cases. It is used to assign or re-assign values to variables.&lt;br /&gt;&lt;br /&gt;Next we have the &lt;em&gt;content.Load&lt;texture2d&gt;(“JesusRocks“);&lt;br /&gt;&lt;/em&gt;&lt;br /&gt;This looks like a complicated statement but is actually quite simple. First we access the &lt;em&gt;content&lt;/em&gt; variable. If you look to where you placed your Texture2D variable declaration, above it somewhere, you will see two more variable declarations. These are created there by default and are used for drawing and loading graphics. The second one down is the &lt;em&gt;ContentManager content&lt;/em&gt; variable declaration and is just creating a ContentManager class and naming it &lt;em&gt;content&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;This variable is initialized(set to a value) in the constructor and is done so by default.&lt;br /&gt;Now back where we are loading our &lt;em&gt;myTexture&lt;/em&gt; variable we can use this &lt;em&gt;content&lt;/em&gt; variable to help with loading. It so happens that the ContentManager class has a method(a group of code that we can call) that is called &lt;em&gt;Load&lt;/em&gt;. We access this method by using &lt;em&gt;content.Load&lt;/em&gt;. We use the dot to access all the available methods that the &lt;em&gt;content&lt;/em&gt; variable has stored within.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;After the &lt;em&gt;content.Load&lt;/em&gt; we have &lt;em&gt;&lt;texture2d&gt;("JesusRocks");&lt;/em&gt;&lt;texture2d&gt;. All this does is, since we want to load a Texture2D, we have to pass this in as a parameter. A parameter is just some external information that the method we are calling needs in order to operate correctly. In our case, the &lt;em&gt;Load&lt;/em&gt; method of the ContentManager class needs to know which type of gphic object we are loading, so we pass in Texture2D. We have the &lt;&gt; symbols because this method is a type of special method. Usually, methods take parameters in between the () symbols. But in this case a parameter was passed in between the &lt;&gt; symbols. This is actually because this method is called a generic method. When we call this method, we need to pass a class between the &lt;&gt; symbols. What I mean by this is, if you try to pass &lt;em&gt;myTexture&lt;/em&gt; in between the &lt;&gt; symbols, it won’t work. Even though the &lt;em&gt;myTexture&lt;/em&gt; variable is a type of the Texture2D class, we need to actually pass in a class. Again the same thing when we call the () symbols following the &lt;&gt;. We need to pass in a variable, not a class. In our case, the &lt;em&gt;Load&lt;/em&gt; method is generic so it needs both sets of parameter types. In the &lt;&gt; symbols we pass in a class name, which is a Texture2D. We say a Texture2D and not some other class because our &lt;em&gt;myTexture&lt;/em&gt; variable is a Texture2D so it makes sense.&lt;br /&gt;&lt;br /&gt;After the first set of parameter symbols, we have the () symbols. These are where we pass in variable parameters. We pass in a string which refers to the name of our image that we loaded. As you may notice, we have excluded the file extension because it is not needed and can not be used when you pass in the string. Also, going back to parameter types, since I need a string as a parameter in between the () symbols, I pass in an already initialized string. If I had passed in the class name, &lt;em&gt;String&lt;/em&gt;, it would not work. It is all pretty easy to tell the difference because it depends on whether you are using the &lt;&gt; symbols or the () symbols.&lt;br /&gt;&lt;br /&gt;The texture name that I loaded into my project is called &lt;em&gt;JesusRocks&lt;/em&gt;, so I passed that in between the () symbols. I also put quotation marks before and after the, &lt;em&gt;JesusRocks&lt;/em&gt;, to symbolize that this is a string and not a variable name.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may be wondering how I had known that I was to pass in a string into the () symbols. If you just type(or re-type) the first parenthesis, you will see that a tan box comes up showing the name of the method and then all parameters needed. In this case, the tan box shows that I need a string. &lt;/p&gt;&lt;a href="http://bp3.blogger.com/_kLtxSdyLIgE/RtmuhOAIrUI/AAAAAAAAACc/YhA1iYv9pw0/s1600-h/ScreenShot5.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105303538318748994" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_kLtxSdyLIgE/RtmuhOAIrUI/AAAAAAAAACc/YhA1iYv9pw0/s400/ScreenShot5.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;Figure 1-5 The Tan Box Showing That I Need a String as a Parameter&lt;/strong&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;br /&gt;Finally, I end the statement with a semicolon. Because there are not two curly braces following the end of this statement(line of code), I end with a semicolon. &lt;/div&gt;&lt;br /&gt;Phew, that was a very long step and I really hope that didn’t confuse you, but eventually, you will get the hang of it. Now time to draw.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RtmzSeAIrbI/AAAAAAAAADU/2BnYnapCU2M/s1600-h/ScreenShot6.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105308782473817522" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtmzSeAIrbI/AAAAAAAAADU/2BnYnapCU2M/s400/ScreenShot6.jpg" border="0" /&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;/a&gt;&lt;/p&gt;&lt;strong&gt;Figure 1-6 The Code Inside the LoadGraphicsContent Method &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;Step 4-Draw the image onto the screen each frame&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Now comes the fun part. Actually seeing what you are doing. If you run the code right now(F5) then you will see only a blue screen. This is because we haven’t called any method to draw our texture. First before we do any drawing, we need a SpriteBatch. A SpriteBatch is a class Microsoft has let us use that allows us to draw images to the screen. In order to use this class, we must create a variable for it. Just like we did for the Texture2D variable, create a SpriteBatch variable:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;span style="color:#3333ff;"&gt;private&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;SpriteBatch&lt;/span&gt; mySpriteBatch; &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RtmvCeAIrWI/AAAAAAAAACs/49smHVoMDVM/s1600-h/ScreenShot7.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105304109549399394" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtmvCeAIrWI/AAAAAAAAACs/49smHVoMDVM/s400/ScreenShot7.jpg" border="0" /&gt;&lt;/p&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RtmvCeAIrWI/AAAAAAAAACs/49smHVoMDVM/s1600-h/ScreenShot7.jpg"&gt;&lt;p align="center"&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;Figure 1-7 Our SpriteBatch Variable Declaration&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;After we have named our SpriteBatch variable, we must initialize it. In the &lt;em&gt;Initialize&lt;/em&gt; method, type this code inside of the method. &lt;/p&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch = new &lt;span style="color:#66cccc;"&gt;SpriteBatch&lt;/span&gt;(graphics.GraphicsDevice); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All this code is doing is assigning the value of our SpriteBatch variable that we created, to a new SpriteBatch class. We use the &lt;em&gt;new&lt;/em&gt; keyword to specialize that we want to create a new ‘something‘. Then we place the name of the class we want to create(we put a SpriteBatch because our &lt;em&gt;mySpriteBatch&lt;/em&gt; variable is a SpriteBatch).&lt;br /&gt;&lt;br /&gt;After the name of the class you see what looks like a parameter. This actually is a parameter. We are calling the constructor of the SpriteBatch class. A constructor is like a method that helps create a class. Every class has one and it looks like a method. The constructor of the SpriteBatch class takes the parameter of a GraphicsDevice class. A GraphicsDevice is a class that helps with drawing. At the top of our code right above the ContentManager variable declaration, you see a GraphicsDeviceManager variable declaration. This variable is named &lt;em&gt;graphics&lt;/em&gt;. Again, like the ContentManager variable, &lt;em&gt;graphics&lt;/em&gt; is initialized by default. Now since &lt;em&gt;graphics&lt;/em&gt; is a GraphicsDeviceManager, in order to get the GraphicsDevice that is stored inside of the GraphicsDeviceManager class, we need to use the command, &lt;em&gt;graphics.GraphicsDevice&lt;/em&gt; which gets the GraphicsDevice related to the graphics variable.&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5105304109549399410" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtmvCeAIrXI/AAAAAAAAAC0/kA9zVWU1Fnc/s400/ScreenShot8.jpg" border="0" /&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;strong&gt;Figure 1-8 Initializing our SpriteBatch &lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;strong&gt;Note:&lt;/strong&gt; Not all classes have a GraphicsDevice related to them. The GraphicsDeviceManager class does have one though.&lt;br /&gt;&lt;br /&gt;Now that we have our SpriteBatch variable created, we have a sprint to the finish. In the &lt;em&gt;Draw&lt;/em&gt; method, find this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;graphics.GraphicsDevice.Clear(&lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.CornflowerBlue);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code just accesses the GraphicsDevice of the graphics variable, and calls a method of the GraphicsDevice class that clears the screen color to a specified color. By default, this code is there and a color is passed in. This color is &lt;em&gt;CornflowerBlue&lt;/em&gt;. You may change this color if you want. Anyway, after this statement, place this code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Begin(&lt;span style="color:#66cccc;"&gt;SpriteBlendMode&lt;/span&gt;.AlphaBlend);&lt;br /&gt;mySpriteBatch.Draw(myTexture, &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;(0, 0), &lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White);&lt;br /&gt;mySpriteBatch.End(); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code actually draws your image onto the screen. First off, we call: &lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Begin(&lt;span style="color:#66cccc;"&gt;SpriteBlendMode&lt;/span&gt;.AlphaBlend); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code calls the &lt;em&gt;Begin &lt;/em&gt;method of the SpriteBatch class, which is required to get the &lt;em&gt;mySpriteBatch&lt;/em&gt; variable ready for drawing. We pass in a certain blend mode as a parameter. A blend mode is just a way that you want to draw the sprites. &lt;em&gt;SpriteBlendMode.AlphaBlend&lt;/em&gt; is just saying that you want to draw your sprites using transparency(alpha is the transparency value of an image).&lt;br /&gt;&lt;br /&gt;Then we have the meat of the code:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.Draw(myTexture, &lt;span style="color:#3333ff;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Vector2&lt;/span&gt;(0, 0), &lt;span style="color:#66cccc;"&gt;Color&lt;/span&gt;.White); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This code calls the &lt;em&gt;Draw&lt;/em&gt; method of the SpriteBatch class. This method is the first method we have used that takes more than one parameter.&lt;br /&gt;&lt;br /&gt;First off, the method needs a Texture2D variable to actually draw. We pass in our &lt;em&gt;myTexture&lt;/em&gt; variable. Then, after a comma, which is needed to separate one parameter from the next, the method needs a position to draw the sprite at. The method is asking for a Vector2 which is a class that holds the x and y coordinates of anything. Instead of passing in an already created variable, we can also just create a variable right there and then, inside of the method call. We do this by just saying, &lt;em&gt;new Vector2(0, 0)&lt;/em&gt;. As you may recognize, we are again calling the constructor of a class. This time we are calling the constructor of the Vector2 class. This constructor takes two parameters, an x and a y coordinate. We specify, 0, 0 to say that we want to draw the sprite at the top-left corner of the screen. Lastly, we pass in a color to taint our sprite with. This can be used to show if a certain sprite is selected. In our case we don’t want our sprite to be tainted with any color, so we specify &lt;em&gt;Color.White&lt;/em&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RtmzSeAIraI/AAAAAAAAADM/bTCzaSMNm1w/s1600-h/ScreenShot9.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105308782473817506" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/RtmzSeAIraI/AAAAAAAAADM/bTCzaSMNm1w/s400/ScreenShot9.jpg" border="0" /&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;/a&gt;&lt;/p&gt;&lt;strong&gt;Figure 1-9 The Code to Draw Our Sprite&lt;/strong&gt;&lt;br /&gt;&lt;p align="left"&gt;&lt;br /&gt;Lastly, we end with:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;mySpriteBatch.End(); &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This calls the &lt;em&gt;End&lt;/em&gt; method of the SpriteBatch class. This method takes no parameters, but we still have to place the two parentheses. The &lt;em&gt;End&lt;/em&gt; method actually draws the sprites on the screen.&lt;br /&gt;&lt;br /&gt;Now if you press F5(or click the green arrow on the top of the page), you can see your sprite drawn on the screen:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/RtmvCuAIrZI/AAAAAAAAADE/SOG4w2S6PFg/s1600-h/ScreenShot10.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5105304113844366738" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/RtmvCuAIrZI/AAAAAAAAADE/SOG4w2S6PFg/s400/ScreenShot10.jpg" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p align="center"&gt;&lt;/a&gt;&lt;/p&gt;&lt;strong&gt;Figure 2.0 The Final Result-Our Sprite Drawn on The Screen &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p align="left"&gt;Even though you didn’t specify anything about frames, since you placed your drawing code inside the &lt;em&gt;Draw&lt;/em&gt; method, the sprite is drawn every frame. Now maybe you are wondering why the top-left point of the sprite is drawn at position 0, 0, instead of maybe the center of the sprite. This is because the origin(main position) of your sprite is set by default at the top-left corner of your image. You can change the origin of where your sprite is drawn at, but we will not go through that today.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p align="left"&gt;Now, after a lot of work, you have drawn a sprite on the screen.&lt;br /&gt;&lt;br /&gt;If you have any questions or requests, post a comment.&lt;/p&gt;Thanks&lt;br /&gt;&lt;br /&gt;If you need something, pray.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-2692387817239561752?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/2692387817239561752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=2692387817239561752' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2692387817239561752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2692387817239561752'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/drawing-our-first-sprite.html' title='Drawing Our First Sprite'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_kLtxSdyLIgE/Rtm06eAIrcI/AAAAAAAAADc/8zfi5ptRcjY/s72-c/ScreenShot1.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-2692644483551701814</id><published>2007-08-31T16:40:00.001-07:00</published><updated>2007-09-08T17:45:04.162-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 2 -- Drawing Our First Sprite</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial shows you how to draw a sprite onto the screen. You do not need any coding experience in order to complete this tutorial.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;A windows game project (created in Tutorial 1)&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;View the tutorial here &lt;a href="http://christiangameprogramming.blogspot.com/2007/08/drawing-our-first-sprite.html"&gt;Tutorial 2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If you need something, pray.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-2692644483551701814?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/2692644483551701814/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=2692644483551701814' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2692644483551701814'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2692644483551701814'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/tutorial-2-drawing-our-first-sprite.html' title='Tutorial 2 -- Drawing Our First Sprite'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-1730131866402211302</id><published>2007-08-31T14:58:00.000-07:00</published><updated>2007-11-15T19:27:05.239-08:00</updated><title type='text'>Creating a New Project</title><content type='html'>&lt;div align="left"&gt;&lt;span style="font-family:trebuchet ms;"&gt;The first step in this tutorial series that needs to be completed is to create the project in which we will be working in.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;First, we want to open up the programming environment. From the desktop, locate the C# Express Edition and open it. You should be greeted with the Start Page.&lt;br /&gt;&lt;/span&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/RtiiJuAIrMI/AAAAAAAAABc/7cZ__niherk/s1600-h/ScreenShot2.jpg"&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/Rz0M4fcdJpI/AAAAAAAAAJM/qhif6AgI3rQ/s1600-h/StartPage.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5133273314925291154" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/Rz0M4fcdJpI/AAAAAAAAAJM/qhif6AgI3rQ/s400/StartPage.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Figure 1:&lt;/strong&gt; You should first be greeted with the Start Page. &lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;div align="left"&gt; &lt;/div&gt;&lt;div align="left"&gt;Now we want to create a project. This project is where we will type our code into. Project templates are just already made projects which come with code that starts you off in a given direction. The template we want to use is the Windows Game template. In order to create a Windows Game you need to navigate to the menu and select &lt;strong&gt;File / New Project&lt;/strong&gt;. &lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;a href="http://bp0.blogger.com/_kLtxSdyLIgE/Rz0M4PcdJoI/AAAAAAAAAJE/aHtIYKAJnOg/s1600-h/FileNewProjectStartPage.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5133273310630323842" style="CURSOR: hand" alt="" src="http://bp0.blogger.com/_kLtxSdyLIgE/Rz0M4PcdJoI/AAAAAAAAAJE/aHtIYKAJnOg/s400/FileNewProjectStartPage.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 2:&lt;/strong&gt; Select File / New Project to start creating the project.&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;Now you should see a list of different project templates that you can choose from. In our case, we want to create a Windows Game. We want a Windows Game because then we are already supplied with the code to get working on game elements. It is much easier to choose Windows Game when working on a game project, but you can create the exact same thing by choosing a different project template.After selecting Windows Game, change the name of your project. I am going to change the name of my project to TutorialProject. If you don’t like this name, feel free to choose something else. For now, you do not need to worry about the other directory options; just leave them as they are for now (right now, all the default options are what we want. When we need to change these options, I will tell you). &lt;/div&gt;&lt;/span&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;a href="http://bp1.blogger.com/_kLtxSdyLIgE/Rz0M4fcdJqI/AAAAAAAAAJU/Ku1iCwpTz9E/s1600-h/CreateTutorialProject.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5133273314925291170" style="CURSOR: hand" alt="" src="http://bp1.blogger.com/_kLtxSdyLIgE/Rz0M4fcdJqI/AAAAAAAAAJU/Ku1iCwpTz9E/s400/CreateTutorialProject.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;strong&gt;Figure 3:&lt;/strong&gt; Create a Windows Game project. I named my project TutorialProject.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;span style="font-family:trebuchet ms;"&gt;Now you have officially created a Windows Game project. As I was telling you, by creating a Windows Game, you can already build (run) the project and get a nice looking blue screen. Do this now if you want by pressing F5, or by clicking the green arrow at the top of the screen. &lt;/span&gt;&lt;/div&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;div align="left"&gt;&lt;br /&gt;&lt;a href="http://bp2.blogger.com/_kLtxSdyLIgE/Rz0M4vcdJrI/AAAAAAAAAJc/VfG9WHVzt24/s1600-h/CornflowerBlueScreen.jpg"&gt;&lt;img id="BLOGGER_PHOTO_ID_5133273319220258482" style="CURSOR: hand" alt="" src="http://bp2.blogger.com/_kLtxSdyLIgE/Rz0M4vcdJrI/AAAAAAAAAJc/VfG9WHVzt24/s400/CornflowerBlueScreen.jpg" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Figure 4:&lt;/strong&gt; If you run the project now (F5) you will be greeted with a very friendly cornflower blue screen.&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;If you have any troubles or requests, leave a comment and I will try to answer you. &lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;Thanks to the Lord Jesus Christ for helping me do these tutorials and helping me solve all my problems. He is all there is to life.&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-1730131866402211302?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/1730131866402211302/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=1730131866402211302' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1730131866402211302'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/1730131866402211302'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/starting-new-project.html' title='Creating a New Project'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_kLtxSdyLIgE/Rz0M4fcdJpI/AAAAAAAAAJM/qhif6AgI3rQ/s72-c/StartPage.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-8978665398184740083</id><published>2007-08-31T14:51:00.000-07:00</published><updated>2007-10-01T21:16:32.872-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='2D Tutorials'/><title type='text'>Tutorial 1 -- Starting a new Project</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This tutorial shows a introduction to starting an XNA project. This project will be the project that we will use for the following 2D Basic tutorials.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;C# Express Edition&lt;br /&gt;XNA version 1.0&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;View the tutorial here: &lt;a href="http://christiangameprogramming.blogspot.com/2007/08/starting-new-project.html"&gt;Tutorial 1&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Remember&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The Lord is all there is to life.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-8978665398184740083?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/8978665398184740083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=8978665398184740083' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8978665398184740083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/8978665398184740083'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/tutorial-1-starting-new-project.html' title='Tutorial 1 -- Starting a new Project'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-2603938082607655852</id><published>2007-08-23T11:21:00.000-07:00</published><updated>2007-11-21T13:11:39.771-08:00</updated><title type='text'>XNA and C# Download Instructions</title><content type='html'>&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;If you have come to the decision that you want to engage in the XNA world and learn to program games in C#, then you will need some tools. This post will hopefully help you find the downloads.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;First, make sure your computer meets the &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb203918.aspx"&gt;&lt;span style="font-family:trebuchet ms;"&gt;System Requirements for C# and XNA&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Next, you need to download and install the &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/express/aa975050.aspx"&gt;&lt;span style="font-family:trebuchet ms;"&gt;C# Express Edition&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;After that, go ahead and download and install the &lt;/span&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=7B0B0339-613A-46E6-AB4D-080D4D4A8C4E&amp;amp;displaylang=en"&gt;&lt;span style="font-family:trebuchet ms;"&gt;Service Pack 1&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; for the C# Express Edition. If you have a Windows Vista operating system, then you should download and install the &lt;/span&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=90e2942d-3ad1-4873-a2ee-4acc0aace5b6&amp;amp;displaylang=en"&gt;&lt;span style="font-family:trebuchet ms;"&gt;Windows Vista Service Pack 1 Update&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Now, download and install &lt;/span&gt;&lt;a href="http://msdn2.microsoft.com/en-us/xna/aa937795.aspx"&gt;&lt;span style="font-family:trebuchet ms;"&gt;XNA Game Studio Express&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Finally, if you want to develop games for the Xbox 360, there is a &lt;/span&gt;&lt;a href="http://creators.xna.com/Headlines/gettingstarted/archive/2007/02/02/Video_3A00_-Getting-Started-with-the-XNA-Creators-Club.aspx"&gt;&lt;span style="font-family:trebuchet ms;"&gt;Video&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt; that will help you with this task.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;strong&gt;Note:&lt;/strong&gt; There is actually a newer version of XNA, XNA 2.0 (Beta) but I am not using that version yet in any of the tutorials.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;Once all these steps have been completed, you should be up and ready to get started creating your very first small games. If you don't know C#, there are two simple lessons on them located under the &lt;strong&gt;C# Primer&lt;/strong&gt; label. Also, there are some other tutorials for XNA under the &lt;strong&gt;Question and Answer&lt;/strong&gt; label and the &lt;strong&gt;Tutorial&lt;/strong&gt; label. If you have any requests for tutorials, please, ask for them. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:trebuchet ms;"&gt;I hope that you are able to fully suceed in your gaming quest and finally, I hope that you will understand the peace and hope that comes with accepting the Lord Jesus Christ. Thanks again.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-2603938082607655852?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/2603938082607655852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=2603938082607655852' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2603938082607655852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/2603938082607655852'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/xna-and-c-download-instructions.html' title='XNA and C# Download Instructions'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2903756005659412185.post-6269890934820042617</id><published>2007-08-23T11:13:00.000-07:00</published><updated>2007-11-16T17:17:04.373-08:00</updated><title type='text'>What is XNA?</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;What is XNA? That is a very good question. While XNA is not a programming language, XNA is a game development huge class library. By using the classes that are stored in the XNA namespaces, any games from 2D to 3D to RPG to RTS are in reach. Microsoft has really outdone themselves by enabling the easy ability to create games using XNA.&lt;br /&gt;&lt;br /&gt;Some may think that XNA was built off of managed DirectX. Well, even though XNA shows many similarities between DirectX, XNA was built completely from scratch. Also, unlike managed DirectX, XNA does not require &lt;u&gt;&lt;strong&gt;any&lt;/strong&gt;&lt;/u&gt; device creation! This saves tons of time when trying to learn the boring stuff and not even seeing any results.&lt;br /&gt;&lt;br /&gt;Finally, it is useful to mention that XNA was made for the C# programming language, and to my knowledge does not fully support any other languages. However, I am not sure if it supports Visual Basic or not. I program in C#, but if you love Basic, I recommend searching to see if XNA is supported in that language. I do know though that there is a wonderful XNA community and forum at &lt;/span&gt;&lt;a href="http://creators.xna.com/"&gt;&lt;span style="font-family:trebuchet ms;"&gt;http://creators.xna.com/&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;. This community uses the C# language (there is section that uses C++, but this section talks about DirectX and not XNA).&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2903756005659412185-6269890934820042617?l=christiangameprogramming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://christiangameprogramming.blogspot.com/feeds/6269890934820042617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2903756005659412185&amp;postID=6269890934820042617' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6269890934820042617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2903756005659412185/posts/default/6269890934820042617'/><link rel='alternate' type='text/html' href='http://christiangameprogramming.blogspot.com/2007/08/what-is-xna.html' title='What is XNA?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/11293668203909748441</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
