Posts
  • File → New Project

    Microsoft Developer Day at GDC

    • 4 Comments

    GDCMicrosoftDayOn Tuesday, March 6th from 10:00 AM to 5:30 PM, Microsoft will be holding a session at the Game Developers Conference to introduce developers to the future of games and entertainment. They'll be doing deep dives on Xbox LIVE and Windows 8, where you can learn about how you can take advantage of Microsoft's vision for connected entertainment.

    The primary audience for this Developer Day is professional developers who build games and entertainment applications for Xbox 360 and Kinect, Windows 8, Windows Phone, and the web. Developers will learn about the new Windows 8 Metro style application platform and new Xbox LIVE services that deliver breakthrough entertainment experiences across all of Microsoft's entertainment platforms.

    Sessions include:

    • Entertainment Reimagined
    • Developing a Great Metro Style Game for Windows 8
    • The Making of Metro Style Marble Maze
    • Async Gaming
    • Xbox LIVE on Windows 8 Deep Dive
    • Xbox LIVE Services – Entertainment Powered by the Cloud
    • Game Data Anywhere Using Xbox LIVE Cloud Storage
    • Asynchronous Gaming with Xbox LIVE Services
    • Connecting Xbox LIVE Web Games with Xbox LIVE Services

    This represents a huge opportunity for game and entertainment application developers to take advantage of the connections being built between the Xbox 360, Windows 8, Windows Phone, and the web. You can get more information about the Microsoft Developer Day by going to the GDC Tutorials page.

  • File → New Project

    Windows 7 Professional RTM – Free for students through MSDNAA

    • 4 Comments

    header_msdnaa2
    Starting today, students and faculty with access to the MSDN Academic Alliance will see a few new products available through their system. The most notable of these products in Windows 7 Professional edition, over two months before it’s available to the general public. I’ve been running Windows 7 since it was first made available in the public beta, and have been very impressed by it’s overall quality, including it’s speed and stability. I currently have four machines running Windows 7, my two work laptops, which are running the RTM Enterprise edition, and two netbooks, running the Release Candidate. I plan to pick up a copy of the RTM for my netbooks when general availability drops on October 22nd, but even the Release candidate is better than any Operating System I’ve run before (and yes, I have run multiple non-Windows OSes).

    Also up on the MSDN AA page is Expression Studio 3. This includes Blend, Design, Web, and Encoder, all of which contain huge improvements from the previous versions. It’s hard to believe that the entire product sweet has been around for less than two years, seeing the quality of the releases. Some things to take a look at inside of Expression Studio 3 are behaviors in Blend (building games in Silverlight just became a lot easier), and the screen recording tool in Encoder. Encoder also supports AVCHD natively now, though you have to have a licensed version to do so. There’s also a preset in there for encoding for the Zune HD, which I have been waiting for patiently since I first heard about it.

    If you don’t have access to MSDN AA, and you are a student or faculty member in a department that focuses on Science, Technology, Engineering, Math, or Design, let me know. I should be able to hook you up with the people to make it happen. And if you have MSDN AA, but you don’t see Windows 7 or Expression Studio 3, check with your administrator, or drop me a comment,and we’ll get that fixed, too. Just imagine rolling up to a buddies house and showing him the Silverlight game you built on your Windows 7 laptop. You know you want this. Go make it happen.

  • File → New Project

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

    • 0 Comments

    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?

    SolutionExplorer

    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.

    Constructor
    1. public Game1()
    2. {
    3.     graphics = new GraphicsDeviceManager(this);
    4.     Content.RootDirectory = "Content";
    5.  
    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.

    Initialize
    1. protected override void Initialize()
    2. {
    3.     // TODO: Add your initialization logic here
    4.  
    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.

    LoadContent
    1. protected override void LoadContent()
    2. {
    3.     // Create a new SpriteBatch, which can be used to draw textures.
    4.     spriteBatch = new SpriteBatch(GraphicsDevice);
    5.  
    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.

    UnloadContent
    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.

    Update
    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();
    6.  
    7.     // TODO: Add your update logic here
    8.  
    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.

    Draw
    1. protected override void Draw(GameTime gameTime)
    2. {
    3.     GraphicsDevice.Clear(Color.CornflowerBlue);
    4.  
    5.     // TODO: Add your drawing code here
    6.  
    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:

    BlueScreenOfLife

    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

    Advanced Movement with Multi-Touch (TriangleShooter)

    • 0 Comments

    Continuing on last week’s article, this week I’ll be showing you an updated way of handling movement using multi-touch. I’ll be starting with the code base from last week, so you can go ahead and get started by downloading that from my SkyDrive share.

    At the end of last week, we had a triangle that was being drawn based on a Vector2 called position. position was being updated based on the TouchPanel state. This means that wherever you touch, that’s where the triangle goes. For some games, this is what we want. But what if you wanted to build a game where you had to navigate through a maze. You start on one side, touch the exit, and bang, you win. Instead, you might want to move towards the touch point. That’s what we’ll be doing here.

    To begin, we need to calculate the difference between where we are now, and where we want to be. To do this, we just subtract the current position from the touch position. Let’s create a new variable in Update called direction, and set it equal to the difference. If we added position and direction, of course, we get the touch position, so changing the update we had to the following will give you the same results we saw earlier.

    Refactoring Using Direction
    1. foreach (TouchLocation tl in TouchPanel.GetState())
    2. {
    3.     Vector2 direction = tl.Position - position;
    4.     position += direction;
    5. }

    We don’t want to move directly to the new location, though, just in that direction. To do this, you can normalize the vector, which means that you create a new vector that points in the same direction as the original, but has a length of one. Once you’ve done that, we get the behavior we wanted.

    Normalizing the Direction
    1. foreach (TouchLocation tl in TouchPanel.GetState())
    2. {
    3.     Vector2 direction = tl.Position - position;
    4.  
    5.     direction.Normalize();
    6.  
    7.     position += direction;
    8. }

    You’ll notice, though, that you move very slowly. To increase the rate of movement, you can multiply the normalized vector.

    Increasing the Movement Rate
    1. foreach (TouchLocation tl in TouchPanel.GetState())
    2. {
    3.     Vector2 direction = tl.Position - position;
    4.  
    5.     direction.Normalize();
    6.  
    7.     position += direction * 10;
    8. }

    If you have a multi-touch capable computer, or if you have a Windows Phone, you can see that putting more than a single finger on the screen makes the triangle move towards both of them. Ideally, we’ll want to set up a primary touch point, and only move towards that. Luckily, touch points are identified uniquely with an int called Id. If we set up an int to track it, let’s call it movementId, we can determine whether a touch point is it, and only move if it is.

    We’ll define movementId up with the other variables:

    Adding movementId Variable
    1. Texture2D triangle;
    2. Vector2 position;
    3.  
    4. int movementId = 0;

    And then modify Update down below. We’ll set the movementId on Pressed, and reset it on Released. If we didn’t reset it on Released, it would work once, then never again. It’s actually interesting to debug and check movementId each time you press on the touch panel. Each time, it increments by one. I’ve also added some code in here to prevent the wiggle you might see as the triangle jumps back and forth over the touch location. Here’s the updated code:

    Updating Based on movementId
    1. foreach (TouchLocation tl in TouchPanel.GetState())
    2. {
    3.     if (tl.State == TouchLocationState.Pressed)
    4.     {
    5.         if (movementId == 0)
    6.         {
    7.             movementId = tl.Id;
    8.         }
    9.     }
    10.  
    11.     if (tl.Id == movementId)
    12.     {
    13.         Vector2 direction = tl.Position - position;
    14.  
    15.         if (direction.LengthSquared() > 100)
    16.         {
    17.             direction.Normalize();
    18.  
    19.             position += direction * 10;
    20.         }
    21.     }
    22.  
    23.     if (tl.State == TouchLocationState.Released)
    24.     {
    25.         if (tl.Id == movementId)
    26.         {
    27.             movementId = 0;
    28.         }
    29.     }
    30. }

    Now only the first finger down will cause movement.

    You’ll notice that the triangle still just points in one direction though. That’s easy enough to address. The SpriteBatch Draw method has an overload that includes an argument of type float called rotation. If we set one of those up, we can pass that over. We’ll start by setting up a variable called rotation:

    Adding rotation Variable
    1. Texture2D triangle;
    2. Vector2 position;
    3. float rotation;

    Then modify Update to get the rotation. We have a Vector2 we called direction, which gives us an X and a Y we can use to find an angle. If you look back at your time in trigonometry, you can remember SOH CAH TOA, Some Old Hippy Caught Another Hippy Tripping On Acid, Sine Opposite Hypotenuse, Cosine Adjacent Hypotenuse, Tangent Opposite Adjacent. Since we have X and Y, Adjacent and Opposite, we want to use Tangent. So tan(theta) = y/x, that means theta = arctan(y/x). We have to be careful here for two reasons. First of all, if X is zero, that’s division by zero, and that’s a problem. Second of all, there is a well known problem in finding out the origin quadrant of the original angle, basically, this means you don’t know the sign. I was given a solution to this when I was giving a presentation at one of the Windows Phone launch events in the Atan2 method. It basically handles all of that for you. So with that in mind, the Update code becomes:

    Getting rotation
    1. foreach (TouchLocation tl in TouchPanel.GetState())
    2. {
    3.     if (tl.State == TouchLocationState.Pressed)
    4.     {
    5.         if (movementId == 0)
    6.         {
    7.             movementId = tl.Id;
    8.         }
    9.     }
    10.  
    11.     if (tl.Id == movementId)
    12.     {
    13.         Vector2 direction = tl.Position - position;
    14.  
    15.         if (direction.LengthSquared() > 100)
    16.         {
    17.             direction.Normalize();
    18.  
    19.             rotation = (float)(Math.Atan2(direction.Y, direction.X));
    20.  
    21.             position += direction * 10;
    22.         }
    23.     }
    24.  
    25.     if (tl.State == TouchLocationState.Released)
    26.     {
    27.         if (tl.Id == movementId)
    28.         {
    29.             movementId = 0;
    30.         }
    31.     }
    32. }

    And finally, we have to modify the Draw function to make use of the new rotation information. The arguments it asks for are:

    • The Texture2D, triangle
    • A Vector2, position
    • A source rectangle, which will determine which portion of the texture to draw, null means the whole thing
    • A Color to tint the Texture2D, white will give you the unmodified texture
    • A float for rotation, which we pass the calculated value
    • A Vector2 that it will treat as the origin about which the texture will be rotated. In this case, I like it to be in the center of the back of the triangle
    • A scale multiplier. 1 will maintain the original size. 0 would reduce it to nothing.
    • SpriteEffects, which would allow you to flip the texture vertically or horizontally
    • A float for layerDepth, the Z-order. Since I’m only drawing one thing, 0 will work.

     

    Drawing Using rotation
    1. spriteBatch.Begin();
    2. spriteBatch.Draw(triangle, position, null, Color.White, rotation, new Vector2(0, triangle.Height / 2), 1f, SpriteEffects.None, 0f);
    3. spriteBatch.End();

    And we’re good to go. Next week, I’ll show how collision works.

    Download the latest version of the source code

  • File → New Project

    Windows Phone 7 Resources

    • 0 Comments

    I’m working with a group at the Microsoft Silicon Valley Campus in Mountain View around learning the Windows Phone 7. As part of the preparation for the group, I searched the web and contacted my team to see what we could use. This is what I’ve come up with so far:

    Windows Phone for Developers
    The primary developer portal for Windows Phone 7
    Programming Windows Phone 7 Series
    The Programming Windows Phone 7 Series book from Charles Petzold is currently available in preview form in three parts. The first part goes over the hardware specifications of the phone and a Hello World application for the Phone. The second part covers Silverlight, and the third covers XNA.
    Learning Windows Phone Programming
    The Learning Windows Phone Programming book by Yochay Kiriaty & Jaime Rodriguez has two chapters available from their book. Chapter 2 introduces Silverlight in the context of the Windows Phone. Chapter 6 also covers Silverlight, but focuses specifically on the additional features available on the phone that aren't in Silverlight 3 specifically. It is split into five parts: User Interface, Security, Networking, Media, and any other run-time differences.
    Application Certification Requirements
    If you are considering developing a game or application for the Windows Phone marketplace, you'll want to read this document. It goes through the technical requirements and policies that must be adhered to in order to be included on the marketplace. One of the complaints I often hear about mobile development is that with a closed marketplace without transparent guidelines like this document, you are basically betting that your application will be accepted, and if you aren't, you are out the development time and resources. It's best to confirm that you meet the guidelines before you begin development.
    Application Platform Overview for Windows Phone
    The Application Platform Overview is a great starting point for getting to understand the Windows Phone. It also contains links to other articles on the MSDN documentation to gain more information on the specifics of the platform.
    Windows Phone UI Design and Interaction Guide
    The Windows Phone has a specifically designed and engineered User Interface, and the recommendation is to model your applications to match, making for a more unified experience requiring less context switching by the user. This document goes over the design and the recommendations for your application.
    Designing Web Sites for Phone Browsers
    What makes a good web site for a desktop browser does not necessarily make a good mobile web site. Whether you plan to simply apply style sheets for mobile browsers, or create a unique mobile site, this document will help to understand the best practices for the mobile web.
    Documentation for Windows Phone 7 at MSDN
    As you develop your game or application for the Windows Phone, you will likely need to look up implementation details for Windows Phone specific features like how the accelerometer was implemented. The documentation on MSDN is a great reference, and you will likely find yourself visiting this site often.

    If you run into other useful resources, please let me know, and I'll add them to the list.

Page 1 of 8 (37 items) 12345»