• File → New Project

    Introduction to XNA–What you get with File –> New Project (TriangleShooter)


    When you start with a new project in XNA, you get some starter code templated out to begin writing your game. In this article, I’m going to walk through what you get. I will be using Visual Studio 2010 Express for Windows Phone, and creating a Windows Phone Game project type. This article is the first in a series that will lead to the creation of the TriangleShooter game I mentioned before.

    What’s in the solution?


    As you can see, the default solution contains two projects. The first project contains the code for your game, and is named whatever you select when you first create the project. In this case, I’ve named the project TriangleShooter, to go along with my game idea. The other project is named as the first project appended with Content, so in my case, TriangleShooterContent, and is a location to place all of your content including graphics, models, audio and video.

    In the primary project, you’ll notice three graphics files. The Background.png file is the image that will be shown on the main page of the phone when you have pinned your application. The GameThumbnail.png will be displayed on the list of all applications installed on the phone to the right of the main page. The Game.ico is an icon used only for Games for Windows, and is not used for Windows Phone or Xbox.

    Program.cs contains the entry point for your project. It’s actually not used in Windows Phone projects, just Windows and Xbox.

    Game1.cs is where we will spend the rest of our time in this article. It gives you everything you need to get started with building a game. Let’s walk through the functions that come standard in a new project.

    1. public Game1()
    2. {
    3.     graphics = new GraphicsDeviceManager(this);
    4.     Content.RootDirectory = "Content";
    6.     // Frame rate is 30 fps by default for Windows Phone.
    7.     TargetElapsedTime = TimeSpan.FromTicks(333333);
    8. }

    The constructor sets up your graphics object, which you will be using to access information about your viewport, orientation, set your game to full screen, and so on.

    1. protected override void Initialize()
    2. {
    3.     // TODO: Add your initialization logic here
    5.     base.Initialize();
    6. }

    The initialize method is used for initializing any variables you have created for your game. My recommendation is to create a function that you will call that resets everything back to their initial values for a new game, which will allow you to just call that function on game reset, saving you from having to write code twice.

    1. protected override void LoadContent()
    2. {
    3.     // Create a new SpriteBatch, which can be used to draw textures.
    4.     spriteBatch = new SpriteBatch(GraphicsDevice);
    6.     // TODO: use this.Content to load your game content here
    7. }

    LoadContent allows you to bring anything over from the Content project. Typical examples include graphics files like PNGs that will come over as Texture2D, WAVs that come over as SoundEffect, and  MP3s that will come over as Song (though you can use them for SoundEffect as well). If you are doing 3D development, you’ll also see files that represent models like X. You can also create custom pipeline projects. I’ll go through one of those in a future article I am working on around sprite sheet animations.

    The spriteBatch that it is initializing is used when drawing 2D graphics and text onto the screen. We’ll be using this a lot.

    1. protected override void UnloadContent()
    2. {
    3.     // TODO: Unload any non ContentManager content here
    4. }

    The UnloadContent method is used for any special loading you did outside of the scope of the LoadContent method. I have actually never put anything into this method.

    1. protected override void Update(GameTime gameTime)
    2. {
    3.     // Allows the game to exit
    4.     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
    5.         this.Exit();
    7.     // TODO: Add your update logic here
    9.     base.Update(gameTime);
    10. }

    Update is the first of two methods, the other being Draw, that will be called over and over in your loop, alternating between the two. Update is where you will handle all of your user input, AI routines, anything that changes stuff around. When processing is taking longer than the 1/30th of a second that it should, Update will be called over Draw, which makes sense because if nothing gets updated, the Draw routine shouldn’t be any different than the last time it was drawn.

    The code inside the block by default checks to see if the user is pressing the back button, and exiting the game if it is. The fact that it is written as if you are pulling state from the first player’s gamepad is actually a really cool thing about using XNA for multiple platforms. That one block of code works for Xbox, Windows, and Phone.

    1. protected override void Draw(GameTime gameTime)
    2. {
    3.     GraphicsDevice.Clear(Color.CornflowerBlue);
    5.     // TODO: Add your drawing code here
    7.     base.Draw(gameTime);
    8. }

    Draw is where you want to put everything that gets displayed on the screen. For a 2D game, you’re going to make a lot of calls to methods in the spriteBatch we initialized earlier.

    The default code simply clears the screen with a beautiful Cornflower Blue. You can actually run the game now, and you’ll get a windows that looks like this:


    I call it the Blue Screen of Life, because you know that everything is working.

    Next up, I’ll walk through everything we need to get some basic gameplay.

  • File → New Project

    PDC Live Event at Microsoft Silicon Valley



    Unless you’ve already got your tickets for PDC this Thursday, it’s not very likely that you are going to be able to attend PDC in person this year. You could take advantage of the streaming video over at the Official Site, or come join us at the Silicon Valley Campus on October 28th for a live stream from PDC, a live keynote by Corporate VP of Strategic and Emerging Business Development, Dan’l Lewin (who is an awesome speaker, BTW), and two additional live sessions. The two live sessions here on campus will be on OData and Windows Phone 7. Attendees will also receive limited edition T-shirts, and have a chance to win an Xbox with Kinect, a Windows Phone 7, and more. You can’t do that at home.

    Registration is available online.

  • File → New Project

    Silicon Valley Code Camp XNA Session


    I am giving a session on XNA for the Windows Phone 7 today at 9:15 AM. For the presentation, I will be walking through the development of a game I am calling Triangle Shooter, because you are a triangle that shoots. I’ve posted the graphics I created to SkyDrive, and after the presentation, I will be posting a series where I walk through the source code and explain how I built the game.


  • File → New Project

    Upcoming XNA Game Development for Windows Phone Webcast



    AT&T is hosting another webcast to follow up their “An Introduction to Tools & Resources for Windows Phone 7 Application Development” on June 24. This time, Rob Cameron will be presenting on Game Development with XNA, and covering the developer tools, the XNA Framework, and resources to help build quality games for the Windows Phone 7.

    If you missed the last session, you can download the slides and presentation from the AT&T Webcast page:

    An Introduction to Tools & Resources for Windows Phone 7 Application Development

    To sign up for the next session, hit up this one:

    XNA Game Development for Windows Phone 7

    You should also check out the XNA Creators Club Online Education Roadmap

  • File → New Project

    Microsoft Kinect Presentation at FDG 2010



    I just got out of a presentation on the Kinect (formerly Project Natal) at the Foundations of Digital Games 2010 conference in Monterey, California. This is the second time I’ve seen the Kinect in action, and it’s come a long way. The demonstration started with an overview of the platform, including the traditional camera, depth sensor and microphone array. They showed a visualization software showing what the camera saw and how it mapped that into a game ready skeleton, and then onto the in-game avatar.

    They showed three of the launch titles: Kinect Adventures, Kinect Joyride, and Kinectimals.

    In Kinect Adventures, they showed three minigames: a rafting game, an obstacle course, and a modified and improved version of the Ricochet game showed off in a few venues. The main concept they were showing off was that the games had intuitive controls. They showed some videos they had where they filmed themselves making actions that they thought should be used to control the game, and determined how fun the game would be. They also spoke on the idea of the drop in/drop out mechanic, and how it they encourage multiple players without the need to return to a menu or interrupt their game.

    Kinect Joyride showcased natural gestures. The presenter brought up the idea of everyone understanding the movements related to driving a car. They then went on to talk about how during the development of the game, they found that there were certain gestures that naturally emerged, like leaning into a turn, and how they implemented these in game as gestures that controlled drifting or stunts to give the player extra points.

    boxanimalsThe last game that they showed was by far the cutest. It’s also the game that I think would get the most play at my house, as I’m sure that my daughter would end up spending a good amount of time playing with her virtual pet cat. They showed an RPG element in teaching your pet tricks like jumping, standing on their hind legs, and playing dead. This skill then translated into an obstacle course, where your actions were translated into the actions of the Kinectimal.

    One common thread between all of the games was that the interaction to the game was both natural, and very active. I’ve played a lot with the Wii, and even games like Wii Fit didn’t get me moving at much as the Kinect demo showcased. I’m really looking forward to the launch in November.

    One downside, though, was that someone asked a question about the availability of using the Kinect through XNA. The answer given was that the current access to the Kinect for developers is through the full development kit. I’m hoping that we’ll see XNA developer access once the Kinect launches, as that will give me an even stronger reason to pick one up.

Page 5 of 8 (37 items) «34567»