tag:blogger.com,1999:blog-7704940220772782632024-03-13T13:43:01.795-07:00XNA Game programming talks, tutorials,...~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-770494022077278263.post-91055653193086301082009-03-25T09:48:00.000-07:002009-03-25T09:49:18.657-07:00Dream Build Play 2009 and XNA Game Studio 3.1 Announced at GDC!Good news...~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com0tag:blogger.com,1999:blog-770494022077278263.post-36873689944775518722009-03-08T10:48:00.000-07:002009-03-09T23:53:27.105-07:00Hello, our first componentLet's redo our "Hello World" game, but in another way.<br />This time will make an "Hello World" component.<br /><br />This time, we will not directly code in our Game class, we will create a Component and simply use it in our game.<br /><br />Create a XNA 3.0 Windows Game project from scratch with the wizard (let's name it <span style="font-style: italic;">HelloComponents</span>), then add a a sprite font content to our project (like the steps 0 & 1 of the previous tutorial).<br /><br /><span style="font-weight: bold;">Step 1: <span style="font-style: italic;">Create our Hello World Component</span></span><br />To create our component:<br /><ol><li> In our project in the solution explorer: Right click on our (<span style="font-style: italic;">HelloComponents</span>)project node<br /></li><li>In the popup menu: Choose Add</li><li>In the submenu: Choose New Item</li><li>In the categories tree: Choose <span style="font-style: italic;">Visual C# Items/XNA Game Studio 3.0</span><br /></li><li>In the template list: Choose <span style="font-style: italic;">Game Component</span><br /></li><li>Rename our game component: For this tutorial, please, name your component '<span style="font-style: italic;">HelloComponent</span>'</li><li>Then: Click on Add</li></ol>By default new Game Component inherit from <span style="font-style: italic; color: rgb(51, 102, 102);">GameComponent</span> class. This class is usable for us now, because it is not 'drawable'. So just change the base class of our component to <span style="font-style: italic; color: rgb(51, 102, 102);">DrawableGameComponent</span> .<br /><br /><span style="font-weight: bold;">Step 2:</span> <span style="font-weight: bold; font-style: italic;">Customize our component</span><br />We need 2 fields. One for the sprite font like in the previous tutorial and one for the sprite batch because in the previous tutorial we use the game's one, but the wizard does not add one in component.<br /><div class="codeBloc"><span style="color: rgb(51, 102, 102);">SpriteBatch </span>spriteBatch;<br /><span style="color: rgb(51, 102, 102);">SpriteFont </span>myFont;<br /></div><br />Then we need to override two methods. First one to load the sprite font content and create the sprite batch. Second one to actually display the text.<br /><div class="codeBloc">protected override void LoadContent()<br />{<br /><span style="color: rgb(0, 0, 153);">base</span>.LoadContent();<br /><br />spriteBatch = new <span style="color: rgb(51, 102, 102);">SpriteBatch</span>(GraphicsDevice);<br />myFont = Game.Content.Load<<span style="color: rgb(51, 102, 102);">SpriteFont</span>>("MyFont");<br />}</div><br /><br />and<br /><div class="codeBloc"><span style="color: rgb(0, 0, 153);">public override void</span> Draw(<span style="color: rgb(51, 102, 102);">GameTime </span>gameTime)<br />{<br /><span style="color: rgb(0, 0, 153);">base</span>.Draw(gameTime);<br /><br />spriteBatch.Begin();<br />spriteBatch.DrawString(myFont, <span style="color: rgb(102, 0, 0);">"Hello components' World"</span>, <span style="color: rgb(51, 102, 102);">Vector2</span>.Zero, <span style="color: rgb(51, 102, 102);">Color</span>.Yellow);<br />spriteBatch.End();<br />}</div><br /><br /><span style="font-weight: bold;">Step 3:</span> <span style="font-weight: bold; font-style: italic;">Add our component to our game</span><br />In our game class, in the Initialize method, just add a line:<br /><div class="codeBloc"><span style="color: rgb(0, 0, 153);">protected override void</span> Initialize()<br />{<br />Components.Add(new <span style="color: rgb(51, 102, 102);">HelloComponent</span>(<span style="color: rgb(0, 0, 153);">this</span>));<br /><span style="color: rgb(0, 0, 153);">base</span>.Initialize();<br />}</div><br /><br />That's all.~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com0tag:blogger.com,1999:blog-770494022077278263.post-2955141215538217962009-03-05T08:00:00.001-08:002009-03-08T11:11:30.126-07:00Very First Step with XNA framework (part 2/2) : Hello WorldEh, what's up? Ready for an exiting tutorial.<br /><br />Today we will code our first XNA game... hmm... not really a game. Let's say a classic "Hello World" program.<br /><br /><span style="font-weight: bold;">Step 0: <span style="font-style: italic;">Create our project</span></span><br />Let's create a new project with Visual Studio Project Creation Wizard.<br /><ol><li>Menu: Choose <span style="font-style: italic;">File</span></li><li>Menu: Choose <span style="font-style: italic;">New Project</span></li><li>In Project types tree: Choose <span style="font-style: italic;">XNA Game Studio 3.0</span></li><li>In Templates list: choose <span style="font-style: italic;">Windows Games (3.0)</span></li><li>In the footer: Name your project</li><li>In the footer: Choose your project Location</li><li>Then: Click OK</li></ol> <span style="font-weight: bold;">Step 1:</span><span style="font-weight: bold; font-style: italic;"> We need a font</span><br />There is many way to create font. Remember that in all the ways, fonts are 2D textures with some extra informations to locate letter in their canvas.<br />I will show the simplest method. We will just use a Windows Font and the built-in font importer/converter to do the job for us.<br /><br />Let's add our font sprite resource.<br /><ol><li> In our project in the solution explorer: Right click on Content</li><li>In the popup menu: Choose Add</li><li>In the submenu: Choose New Item</li><li>In the template list of the poping dialog box: Choose Template Sprite Font</li><li>Rename our font: For this tutorial, please, name your font 'MyFont'</li><li>Then: Click on Add</li></ol>Let's open our font resource file to customize our font. Just double-click on it in the solution explorer. 'spriteresource' files are, in fact, XML files describing the font attributes. We can freely modify it and choose font name, size, style, spacing, and character regions.<br />Let's choose <span style="font-style: italic;">Arial</span>, <span style="font-style: italic;">20</span>, <span style="font-style: italic;">Regular</span>, <span style="font-style: italic;">0</span>, and <span style="font-style: italic;">32 </span>to <span style="font-style: italic;">126</span>. Save the file and close it.<br /><br /><span style="font-weight: bold;">Step 2: <span style="font-style: italic;">Load the font</span></span><br />Now we need to load it in our game.<br /><br />First, please add a <span style="font-style: italic;">SpriteFont </span>variable in your. Let's name it <span style="font-style: italic;">myFont</span>.<br />Then, in the LoadContent method, let's add this line :<br /><div class="codeBloc"> myFont = Content.Load<<span style="color: rgb(51, 153, 153);">SpriteFont</span>>(<span style="color: rgb(102, 0, 0);">"MyFont"</span>); </div><br /><br /><span style="font-weight: bold;">Step 3: <span style="font-style: italic;">Display the text</span></span><br />Now we will modify our Draw method to display our text.<br />XNA built-in text display use a SpriteBatch object to display.<br /><br />Just add the 3 lines just after the GraphicsDevice.Clear(...); line<br /><div class="codeBloc"> spriteBatch.Begin();<br />spriteBatch.DrawString(myFont, <span style="color: rgb(102, 0, 0);">"Hello World!"</span>, <span style="color: rgb(51, 153, 153);">Vector2</span>.Zero, <span style="color: rgb(51, 102, 102);">Color</span>.White);<br />spriteBatch.End();<br /></div><br />That's all. Run your game and enjoy.~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com0tag:blogger.com,1999:blog-770494022077278263.post-76265432327987139942009-03-02T13:16:00.001-08:002009-03-06T04:16:31.127-08:00Very First Step with XNA framework (part 1/2)There is so many things to say. I guess many other sites (especially the<a href="http://creators.xna.com/">XNA community site</a>) deals with many samples and tutorials. I invite you to view these sites. For my part, I will only address the outline.<br /><br />Creating the solution and project for your game is very simple thanks to the Wizard for creating Visual project.<br /><br />The core of your game will be implemented in a class inherited from <span style="font-family:courier new;">Microsoft.Xna.Framework.<span style="color: rgb(51, 153, 153);">Game</span></span><br />All you have to do is implement 6 methods of this call to make a game.<br />Theses methods are : the <span style="font-style: italic;">constructor</span>, <span style="font-style: italic;">Initialize</span>, <span style="font-style: italic;">LoadContent</span>, <span style="font-style: italic;">UnloadContent</span>, <span style="font-style: italic;">Update </span>and <span style="font-style: italic;">Draw</span>.<br />That's all. :)<br /><br />Let's describe theses methods.<br /><br /><span style="font-weight: bold; font-style: italic;">Constructor</span><br />By default, there are only two instructions to initialize two values.<br /><br />The first value is <span style="font-style: italic;">graphics </span>a member field of <span style="font-size:100%;"><span style="font-family:Courier New;"><span style="color: rgb(0, 128, 128);">GraphicsDeviceManager</span></span></span> type.<br /><span style="font-size:100%;"><span style="font-family:Courier New;"><span style="color: rgb(0, 128, 128);">GraphicsDeviceManager</span></span></span> is a class that provides access to the functionalities of the graphics hardware.<br /><br />The second value <span style="font-family:courier new;">Content.RootDirectory</span> specifies the location of the assets in the project. By default they are located in the folder named 'Content'. As a general rule you should avoid placing here the code.<br /><br />As a general rule you should avoid placing more code there. But rules can be broken....<br />Generally, that can be done in the constructor can be done in the method 'Initialize' which is there for that.<br /><br /><span style="font-style: italic; font-weight: bold;">Initiliaze method</span><br />It is called just after the creation of the <span style="font-style: italic;">GraphicsDevice</span>.<br /><br />This method is where you should initialize all needed data of your game before its start. It is also where you can query for services, load any non-graphic related content, and add components.<br /><br />You should not forget to call <span style="font-style: italic;font-family:courier new;" ><span style="color: rgb(51, 51, 255);">base</span>.Initialize()</span> to enumerate through any components and initialize them as well, and then invoke the <span style="font-style: italic;">LoadContent </span>method.<br /><br /><span style="font-style: italic; font-weight: bold;">LoadContent</span><span style="font-style: italic; font-weight: bold;"> & </span><span style="font-weight: bold; font-style: italic;">UnloadContent</span><span style="font-style: italic; font-weight: bold;"> </span><span style="font-style: italic; font-weight: bold;"> method</span><span style="font-weight: bold; font-style: italic;">s</span><br />The <span style="font-style: italic;">LoadContent </span>method is called when graphics resources need to be loaded.<br />This <span style="font-style: italic;">UnloadContent </span>method is called when graphics resources need to be unloaded.<br /><br />To load/unload you need a <span style="font-style: italic;">ContentManager</span>... Your game object contains a ContentManager, so in most of the game you do not need to create it yourself (for some reasons it could be a good idea to use your own ContentManagers, but we will see this in a future post).<br /><br />You should not forget to call the method of the base class to call the matching method of all components belonging to your game.<br /><span style="font-style: italic; font-weight: bold;"></span><br /><span style="font-weight: bold; font-style: italic;">Update</span><span style="font-style: italic; font-weight: bold;"> method</span><br />This method contains your game logic. It is called when the game determined that it should be.<br />In it, you should update your game world, check for collisions, gather input, play audio, manage the network, etc...<br /><br />You should not forget to call the <span style="font-style: italic;">Update </span>method of the base class to call <span style="font-style: italic;">Update </span>method of all updatable components belonging to your game.<br /><br /><span style="font-weight: bold; font-style: italic;">Draw</span><span style="font-style: italic; font-weight: bold;"> method</span><br />This is called when the game should draw itself.<br /><br />Avoid placing in this method treatment other than those requested to render your scene on the screen.<br /><br />You should not forget to call the <span style="font-style: italic;">Draw </span>method of the base class to call <span style="font-style: italic;">Draw </span>method of all drawable components belonging to your game.<br /><br /><br />to be continued....~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com0tag:blogger.com,1999:blog-770494022077278263.post-18451276733987746462009-03-02T12:16:00.000-08:002009-03-03T03:14:44.489-08:00What is XNA?XNA game studio is a free tool, provided by Microsoft to ease the development of games for XBox 360, Windows and Zune platforms.<br /><br />Today it is at version 3.0. It is built on top of Microsoft Visual Studio 2008 (no matter the version: standard, profesional, even the express one). Former versions should be used with the Visual Studio 2005 Serie.<br /><br /><div style="text-align: left;" id="result_box" dir="ltr">The XNA is a crossplatform framework that allows the most efficiency on the platform on which it runs. You can manage the access to your graphics, your audio, your inputs, your storage device the same way on each platform. Its pipeline eases the import of many type of assets. The memory is managed that makes the development even easier.<br /><br />You code your game using C#<br /><br />With XNA, Microsoft is the first console maker to give to its community the ability to create its own games and to sell them on the XBox Live marketplace. Note that for this last aspect you must be a premium member (the cost is $99 per year).</div><br />You can see more <a href="http://creators.xna.com/">here</a> on the XNA official community site.<a href="http://creators.xna.com/"><br /></a>~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com0tag:blogger.com,1999:blog-770494022077278263.post-61268471159174010542009-03-02T11:20:00.000-08:002009-03-02T12:13:12.096-08:00And the light was...So this is my first post...<br /><br /><span style="font-style: italic;">You want to know who I am?</span><br />I'm a professional game developer. I've been working on almost all consoles (Xbox360, PS3, Wii, PS2, XBox, NGC, Dreamcast, N64, PC) since 1998.<br />Oh... english is a foreign language for me.<br /><br /><span style="font-style: italic;">Why do I do this blog?</span> <div style="text-align: left;" id="result_box" dir="ltr">This blog is a kind of diary where I will write things that may be interesting (I hope) for XNA developers. I write it in my spare time as well as I develop on XNA.<br />But my real purpose is, if things go well, to describe my experience to develop a game from scratch until it is sold on the Xbox Live Marketplace.<br />I admit that I do not know what this game is yet.<br /></div><br />I'm still discovering C# and XNA... so please be gentle.~iKi~http://www.blogger.com/profile/08515159609659674409noreply@blogger.com1