Sunday, June 5, 2011

XNA Tutorial - Basic Event Handling

One of the most important aspects of any program that is intended to be used by people (i.e. Application Software) is the concept of event handlers. An event is simply some intended user input, like a button push or a mouse-click on something. The programmer must specifically define what actions s/he wants a program to perform and what events those actions should be triggered by. Unless specifically coded somewhere else (such as the default actions for pressing the ‘Windows/Home’ button on a Windows Phone), a programmer must specifically tell the program what events (user actions) to listen for, and what to do for each type of event. If a user performs some input that the programmer wanted, then that triggers some action response from the program.

To recap: a user performs some specific action, if that action is one of the events wired by the programmer, then an appropriate action is performed by the program's event handler. In programmer speak, we say that an event handler 'listens' for events, then 'triggers' an appropriate action once its event is detected. Again this event is just some specific user input.

In this tutorial we will be wiring a bare-bones event handler to listen for user input in the form of a finger tap on an icon. We will create a new WP7 Game that displays that icon, listens for a tap Gesture event occurring on that icon, and then performs a Game exit.



Prerequisites: Be able to create a new Project in Microsoft Visual Studio.

Now that we have a good idea of what we want to do, we can take a look at the default classes that are generated whenever you create a new project.
  • Go ahead and launch MSVS 2010,
  • and select "File > New Project."
  • Select a Windows Phone 7 Game (4.0) project from the XNA Game Studio 4.0 Templates, name the Project "EventHandlerTutorial", and click OK.
  • Double click on the EventHandlerTutorial > Game1.cs class in the Solution Explorer. (If you can't see the Solution Explorer, select "View > Solution Explorer")
If you remove all of the extraneous comments you should have something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace WindowsPhoneGame1
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }

        protected override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            base.Draw(gameTime);
        }
    }
}


In the Solution Explorer,
  • right-click the Game1.cs and select the 'Rename' option.
  • Then rename the file to EventHandlerTutorialGame.cs".
  • When prompted, answer 'yes' to wanting to rename all occurrences of the old class name in the solution.
This is optional, and I will be referring to this class as either 'the main Game class', or as 'EventHandlerTutorial.cs', whichever I feel like at the time.

If you select the correct setting in the "XNA Game Studio Deployment Device" selector (either WP7 Device or Emulator), and start debugging (F5) you will see a solid blue screen. If you press the 'back' button on the phone, the Game will exit back out to the main screen. We will be replicating this effect with an event handler.

  • Right-click on the EventHandlerTutorial project in the Solutions Explorer, and select Add > Class.
  • Name this class "InputState.cs" and click the Add button.

Inside this class we will be tracking the state of the phone's touch screen. We will need a TouchCollection class instance from the Microsoft.Xna.Framework.Input.Touch library, and we will also need a GestureSample class instance from that same library.

Now to the code:
  • Make the InputState class public.
public class InputState
    {
    }
  • Bring the library into scope with a using statement so that we can use the TouchCollection and GestureSample classes.
using Microsoft.Xna.Framework.Input.Touch;


  • Now create a 'Fields' region and
  • declare a public TouchCollection TouchState,
  • and a public readonly List<GestureSample> Gestures,
as below:
#region Fields

        public TouchCollection TouchState;
        public readonly List<GestureSample> Gestures = new List<GestureSample>();
        
        #endregion


  • Create another region and call it "Initialization".
  • Inside this region create the default constructor for the InputState class
It takes no parameters, and it doesn't do anything besides allow us to create instances of this class. It should look as follows:
#region Initialization

        public InputState()
        {
        }
        #endregion

  • Now create yet another region for this class’s Public Methods,
  • and define a public void Update method therein.
This Update method will be what the Game uses to store user input for use in handling events.
  • Inside of it we will need to get the current state of the TouchPanel and store all the Gestures held in that state.
We do this like so:
#region Public Methods

        public void Update()
        {
            // Get user input from the touch panel since last update.
            TouchState = TouchPanel.GetState();

            // Clear the Gesture buffer from last update, so we don't act on it again.
            Gestures.Clear();

            // Add all the stored gestures from the TouchPanel in the Gestures List.
            while (TouchPanel.IsGestureAvailable)
            {
                Gestures.Add(TouchPanel.ReadGesture());
            }
        }
        #endregion

Here is the InputState.cs class in its entirety:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework.Input.Touch;

namespace EventHandlerTutorial
{
    public class InputState
    {
    
        #region Fields

        public TouchCollection TouchState;
        public readonly List<GestureSample> Gestures = new List<GestureSample>();
        
        #endregion

        
        #region Initialization

        public InputState()
        {
        }
        #endregion

        
        #region Public Methods

        public void Update()
        {
            // Get user input from the touch panel since last update.
            TouchState = TouchPanel.GetState();

            // Clear the Gesture buffer from last update, so we don't act on it again.
            Gestures.Clear();

            // Add all the stored gestures from the TouchPanel in the Gestures List.
            while (TouchPanel.IsGestureAvailable)
            {
                Gestures.Add(TouchPanel.ReadGesture());
            }
        }
        #endregion
    }
}



Now that we have a class in which to store our user input, we need to have some means of reading that input and determining if we need to do something because of it. We will do that in the main Game class.
  • Open up the code for the EventHandlerTutorialGame.cs class.
  • Add a field for an InputState class instance
  • and initialize it in the Game's constructor.
#region Fields

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;   
        
        InputState = inputState;

        #endregion
public EventHandlerTutorialGame()
        {
            Content.RootDirectory = "Content";
            graphics = new GraphicsDeviceManager(this);
           
            // Initialize our input storage class.
            inputState = new InputState();                    //<-- HERE
            
            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }
  • Now go to the Update(GameTime) method and put a call to inputState.Update in it.
This way the user's input gets stored every update cycle.
protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Get user input and put all gestures into inputState.Gestures List.
            inputState.Update();                              //<-- HERE
 
            base.Update(gameTime);
        }
Now we need to declare which gestures we want to use as events. Also in the main Game class, go to the Initialize method.
  • Set TouchPanel.EnabledGestures to a Tap gesture.
protected override void Initialize()
        {
            // Tell the TouchPanel to look for Tap type events.
            TouchPanel.EnabledGestures = GestureType.Tap;

            base.Initialize();
        }

So far we are now reading all touch input from the user every update cycle, and we’re listening for Tap gestures. There are really only two things left to do: create an area to tap on, and make the game recognize that it needs to exit when that tap occurs. To create an area to tap on, all we actually need is a Rectangle to perform boundary checks on. We should also add an image so that the user can see where they need to tap. The image is technically optional, as the tap gesture event can be detected without it. Let's create both of these in a single new class.
  • Right-click on the EventHandlerTutorial project and select ‘Add > Class’.
  • Name this class "Button.cs", and make it public.
public class Button
    {
    }
  • Bring the XNA Framework, Framework.Content, and Framework.Graphics libraries into scope with some using statements.
We need them for the Rectangle and Vector2 classes, the ContentManager class, and the SpriteBatch and Texture2D classes respectively.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
In the Fields region
  • put a Rectangle named buttonRectangle,
  • a Texture2D named buttonImage,
  • and a Vector2 named position.
#region Fields

        private Rectangle buttonRectangle;
        private Texture2D buttonImage;
        private Vector2 position;  
        
        #endregion
  • Right-click the buttonRectangle field and select ‘Refactor > Encapsulate Field’ to auto-generate some properties.
  • Repeat the same encapsulation process for the buttonImage
  • and position fields (if you are not using the full version of Visual Studio, you will have to type these out by hand).
  • Put these three properties into a Properties region.
#region Properties

        public Rectangle ButtonRectangle
        {
            get { return buttonRectangle; }
            set { buttonRectangle = value; }
        }
        public Texture2D ButtonImage
        {
            get { return buttonImage; }
            set { buttonImage = value; }
        }
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        #endregion
  • Create an Initialization region, then
  • make a public constructor for the Button class that takes a ContentManager, a string, and a Vector2 as input parameters.
We will have to add an image to the project then load it in when we create the button in our main Game class. But we'll get to that when we're done here. Inside the constructor:
  • load a Texture2D using the passed in string as a reference location and assign it to the buttonImage field,
  • set Position to the passed in Vector2 value,
  • and create a new Rectangle using the X and Y components of Position and the dimensions of buttonRectangle.
The only tricky part here is that you’ll have to cast the Position.X and Position.Y values to integers when you pass them to the Rectangle constructor (they have the float type originally).
#region Initialization

        public Button(ContentManager content, string imagePath, Vector2 position)
        {
            buttonImage = content.Load<Texture2D>(imagePath);

            Position = position;

            buttonRectangle = new Rectangle((int)position.X,
                                            (int)Position.Y,
                                            buttonImage.Width, 
                                            buttonImage.Height);
        }

        #endregion

The last thing we need for the Button class is a Draw method. We’ll have to specifically call it in the main Game class, and it’s probably a good idea if we use the main Game’s SpriteBatch as well. If we just created a SpriteBatch inside the Button class, we would be creating a separate SpriteBatch for every button we put on the screen! So we’ll just pass the main Game’s SpriteBatch in as a parameter.
  • Create a public void Draw method that takes a SpriteBatch class instance as an input parameter.
  • Inside the method call the SpriteBatch.Draw method and pass in the buttonImage and position fields along with a Color.White value.
The first two are obviously to draw what we want, but the last may be new to you. The Color.White is a tint parameter. If you wanted to make the thing you were drawing tinted another color, you could pass that color in place of the White color. Using Color.White basically implies ‘no tint’.
#region Public Methods

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(buttonImage, position, Color.White);
        }

        #endregion

The finished Button.cs class should look like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace EventHandlerTutorial
{
    public class Button
    {
        #region Fields

        private Rectangle buttonRectangle;
        private Texture2D buttonImage;
        private Vector2 position;  
        
        #endregion


        #region Properties

        public Rectangle ButtonRectangle
        {
            get { return buttonRectangle; }
            set { buttonRectangle = value; }
        }
        public Texture2D ButtonImage
        {
            get { return buttonImage; }
            set { buttonImage = value; }
        }
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }
        #endregion


        #region Initialization

        public Button(ContentManager content, string imagePath, Vector2 position)
        {
            buttonImage = content.Load<Texture2D>(imagePath);

            Position = position;

            buttonRectangle = new Rectangle((int)position.X,
                                            (int)Position.Y,
                                            buttonImage.Width, 
                                            buttonImage.Height);
        }

        #endregion


        #region Public Methods

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(buttonImage, position, Color.White);
        }

        #endregion        
    }
}


Up to this point we have an InputState class to get and store all user input gestures, and we have a Button class that displays an image and contains a Rectangle for use in a basic tap-type event. All that remains is to use the Button class in the main Game, and to create a couple methods that handle the user’s input and setup the screen. Before we get to that, we need to add the image we’re going to use as a button icon. Right-click on the EventHandlerTutorialContent(Content) project and select ‘Add > Folder’. Name this folder “Buttons”. You can use any image you want for this really, but I’m going to use this one.
  • Save it to your hard-drive,
  • then right-click the Content Project’s "Buttons" folder and select ‘Add > Existing Item’.
  • Navigate to wherever you saved the button_close.png file, and press the Add button.
Now we can use the image in our project. Inside the EventHandlerTutorial.cs class,
  • add a Button field named button.
  • In the LoadContent method, initialize the Button to a new Button instance and pass in the Game’s ContentManager, the string ‘@”Buttons\button_close”’ (without the single-quotes), and a new Vector2(5f,5f).
Like this:
#region Fields

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;        
        
        InputState inputState;
        Button button;                              //<-- HERE

        #endregion
// Initialize the button, passing in the location for the image file.
            button = new Button(Content, @"Buttons\button_close", new Vector2(5f, 5f));
    
Now in the Draw method, we need to
  • start up the SpriteBatch,
  • Draw the button,
  • then shut the SpriteBatch back down.
protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Draw our close button
            spriteBatch.Begin();
            button.Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }
If you debug the game now, you should see the icon in the top left corner of the screen (in landscape view), but pressing it still doesn’t do anything. I’m going to set the screen to display in portrait mode, because I like it better for this (and because that's the orientation I created all of the example images from :P Back inside the main Game class,
  • create a public void method named InitializePortraitView.
  • Inside the method set the GraphicsDevice’s PreferredBackBufferHeight and PreferredBackBufferWidth properties to 800 and 480 respectively.
  • Add a call to this method in the class constructor.
public void InitializePortraitView()
        {
            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth = 480;
        }
public EventHandlerTutorialGame()
        {
            Content.RootDirectory = "Content";
            graphics = new GraphicsDeviceManager(this);
            InitializePortraitView();                      //<-- HERE
          
            // Initialize our input storage class.
            inputState = new InputState();
            
            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }
Now when the Game runs, it should look like this:




Still inside the main Game class,
  • create a new public void method HandleInput that takes an Input State as a parameter.
Inside the method we’re finally going to get to the meat of the event handler!
  • Create a foreach loop to iterate through the GestureSample List from the InputState class.
  • Inside this foreach loop check whether the current GestureSample is of the GestureType Tap.
  • If it is, then create a Point using the GestureSample’s X and Y coordinates,
  • and check if the button’s Rectangle contains that point.
  • If it does, then exit the Game.
public void HandleInput(InputState input)
        {
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
                    
                    if (button.ButtonRectangle.Contains(tapLocation))
                        this.Exit();
                }
            }
        }
The very last thing we need to do is
  • call this HandleInput method inside the Update method,
specifically after we have updated the InputState for this cycle.
protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Get user input and put all gestures into inputState.Gestures List.
            inputState.Update();

            // Handle some events!
            HandleInput(inputState);
            
            base.Update(gameTime);
        }
The final code for the EventHandlerTutorial.cs class is here:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace EventHandlerTutorial
{
    public class EventHandlerTutorialGame : Microsoft.Xna.Framework.Game
    {
        #region Fields

        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;        
        
        InputState inputState;
        Button button;

        #endregion


        public EventHandlerTutorialGame()
        {
            Content.RootDirectory = "Content";
            graphics = new GraphicsDeviceManager(this);
            InitializePortraitView();
          
            // Initialize our input storage class.
            inputState = new InputState();
            
            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);
        }

        protected override void Initialize()
        {
            // Tell the TouchPanel to look for Tap type events.
            TouchPanel.EnabledGestures = GestureType.Tap;

            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Initialize the button, passing in the location for the image file.
            button = new Button(Content, @"Buttons\button_close", new Vector2(5f, 5f));

        }

        protected override void UnloadContent()
        {
        }

        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Get user input and put all gestures into inputState.Gestures List.
            inputState.Update();

            // Handle some events!
            HandleInput(inputState);
            
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // Draw our close button
            spriteBatch.Begin();
            button.Draw(spriteBatch);
            spriteBatch.End();

            base.Draw(gameTime);
        }

        public void HandleInput(InputState input)
        {
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);
                    
                    if (button.ButtonRectangle.Contains(tapLocation))
                        this.Exit();
                }
            }
        }

        public void InitializePortraitView()
        {
            graphics.PreferredBackBufferHeight = 800;
            graphics.PreferredBackBufferWidth = 480;
        }
    }
}

That’s it! Launch the debugger and check it out. You can now tap the icon and the Game exits, just as if you had pressed the ‘back’ button on your Windows Phone 7 device. That was a bit longer than I was anticipating, but I think it gets the point across. There are other things we could do to spruce this up a bit. We could add a ‘pressed’ condition to the button, that would change the currently drawn image to a darker one while the user is pushing it or for just a moment after the user taps it. We could also create a Screen class that could contain several buttons, each doing something different. But these are going to be the topics for later tutorials. If anything’s not clear, or just seems messed up, leave me a comment and I’ll try to fix it.
I hope this helps someone,
-H

Thursday, June 2, 2011

How to develop your first Windows Phone 7 game in XNA 4.0

Step 1: Install MS Visual Studio 2010
(Assuming you have no versions of MS Visual Studio installed. If you have MSVS 2008 installed, back-up your projects and uninstall XNA 3.x, then uninstall MSVS 2008.)

In order to develop for Windows Phone 7, you're going to need at least Visual Studio 2010 Express (which comes with the Windows Phone 7 development tools). I'm a PhD student at a school
subscribing to the MSDN e-academy, so I have access to MSVS 2010 Pro for free. So I will be doing things that may not be possible with just the Express install that comes with the
Windows Phone 7 dev kit (refactoring methods for example). 
You can go here to see if your school is part of MSDN: 
http://msdn.microsoft.com/en-us/academic/dd861349
And you can get the Windows Phone 7 development tools here:
http://msdn.microsoft.com/en-us/library/ff402530(v=vs.92).aspx.

Before installing the WP7 dev kit, REMOVE XNA GAME STUDIO 4.0!  The WP7 installer will hang for days (literally!) if you have already installed both MSVS 2010 and XNA 4. So go uninstall XNA 4, and come back here when you're done.

Step 2: Install Windows Phone 7 development tools
(Assuming you have MSVS 2010 Pro installed, and NOT XNA 4.0)  The WP7 dev tools come in three parts, and you can get them from the second link above: (THESE SHOULD BE INSTALLED IN THIS ORDER!!!  But first check to see if MSVS 2010 Hotfix KB2486994 has been installed by going to
Control Panel > Programs > Programs and Features > View Installed Updates (See sceenshot00a). 
You should see 'Hotfix KB2486994' under Microsoft Visual Studio 2010 Professional when it has been installed.  

1. vm_web.exe - The installer for MSVS 2010 Express and all of the WP7 framework stuff

2. WindowsPhoneDeveloperResources_en-US_Patch1.msp


3. VS10-KB2486994-x86(/x64).exe - MSVS 2010 update


Another Note: These last two tend to hang for rediculous amounts of time. You can Google the 
problem, but waiting seems to be the only current solution. When I finally got it to work, it took
over an hour to finish vm_web.exe, and about 45min for the 'Hotfix' to finish. They both would
get about 80% done with the install, then just hang for about 30 minutes before finishing up. It
may have something to do with the fact that my setup is consists of Windows 7 Pro x86 installed
via BootCamp on a late 2007 MacBook Pro... but a lot of people have this problem, so maybe not.



Step 3: Creating your first WP7 app!
(This is where we check to see if you have properly configured MSVS 2010)
Before we dive in you need to consider how you will be debugging / running your apps. If you have a WP7 phone (device), then you will need to download, install and run the Zune software bundle. If you don't know what Zune is, think MS's answer to iTunes, and you'd be close. It's been around for a while, but if you are a Mac-tard (like me), then you may not have really noticed it, yet. In order
to connect your device to your computer, you need Zune. So chances are that if you have a compatible device, you already have Zune installed.  If you want to debug on a device, start-up Zune and connect your Windows Phone to your computer via USB. You may need to log in to
Zune as well.  If you don't have a device, or you don't want to use yours to dev with, then you don't really need Zune. Just launch MSVS 2010 Pro.

Now go ahead and select File > New > Project. Then in the pop-up, select a Windows Phone Game(4.0) template. It should be the default, but in case it isn't you can find it in the left hand
panel under Visual C# > XNA Game Studio 4.0. Here you can change the name of your game to whatever you like, but for the purposes of these tutorials, we'll name it 'TacticsRoguer'.
Ensure the 'Create directory for solution' box is checked, then click 'OK'.

If you've connected your device and have Zune running skip this next part. 

Otherwise, change the XNA Gama Studio Deployment Device to 'Emulator' as seen here (screenshot00ba&c).

Now we're ready to debug and run this app! Just press the green right arrow button to 'debug and run'.   If you have a device connected, you should see (I DON'T KNOW YET)  If you are using the Emulator, then you should see a virtual phone pop-up. It will say 'Windows Phone Emulator is doing a complete OS boot' followed by the 'Windows Phone' logo and some scroll dots. Next you'll see
the main phone desktop with the Internet Explorer Icon and an arrow pointing right. DON'T DO ANYTHING! Just wait. The first time you launch and app for a session takes forever. Eventually the emulator will execute the app, turning the emulator screen to the 'Cornflower Blue'
color.  This is the XNA equivalent of a 'Hello World' program.

COMMON ERROR:

"Zune software is not launched. Retry after making sure that Zune software is launched."

FIX:  If you're trying to use your Windows Phone for development, make sure you have Zune running, you're logged in, you have your phone connected, and Zune see's your phone. If you're trying to dev with the emulator, you must select 'Windows Phone 7 Emulator' in the 'Deployment Device Selector'.

COMMON ERROR:
"Out of Memory"

FIX:  If you get this one, the only fix I have found is to shrink the Emulator.




CONGRATULATIONS! You've just deployed your first Windows Phone 7 app!  In order to keep the emulator running, you'll need to click back inside Visual Studio, then press Shift+F5 to cancel the debugging. Pressing F5 or the green arrow will re-debug the app, which you can see happens _much_ faster than it did the first time.

That's it for this tutorial! You should have:
Installed MSVS 2010,
Installed the Windows Phone 7 Dev tools,
Patched both of those,
Created your first WP7 project,
and launched the default WP7 app on either the Emulator or your WP7 device (or even both!)

In the next tutorial we will create an event handler to escape from the app without needing to 'shift-F5' it in MSVS.


See you then!
-H

Friday, May 20, 2011

How to restore MMB functionality in Blender 2.5x on Mac OS X

So I dabble with blender from time to time, and while I'm no expert, I consider myself somewhat accomplished with it. The main difficulty in blender is the _steep_ learning curve. That being said, I still haven't made the transition from 2.4 to 2.5x(until today). One of the first things I noticed is that my middle mouse button ceased to function as it had in 2.49b. After some searching and tweaking, here's what I found.

Problem Statement:
You're trying to run blender 2.5x on Mac OS X >= 10.6.0, but your MMB (alt-click in blender 2.49) has lost its functionality.

SOLUTION:
Modify your default 'User Preferences' to allow the same button configuration from 2.49 to work in 2.5x.
Open up blender 2.5x, and ensure you are in a new project.
Go to 'File' > 'User Preferences...'.
In the panel that opens (Blender User Preferences), select the 'Input' tab at the top.
In the middle of the panel there should now be several expandable nodes: 'Window', 'Screen', 'View2D', etc.
Expand '3D View', then expand '3D View (Global)'.
Press the 'Edit' button on the right.
Click on the 'Middle Mouse' label in the third row(Rotate view).
It should now prompt you with 'Press a key'.
Hold down the alt/option key on the keyboard and click the 'Press a key' label.
The label will change to 'Alt Left Mouse'.
You can then systematically go through that entire list changing every instance of "<key(s)> Middle Mouse" to "<key(s)> Left Mouse" if you want.
(Personally I only change 'Rotate view'(as above), 'Move View'(to 'Shift Alt Left Mouse'), and 'Zoom view'(to 'Ctrl Left Mouse'))
When you are done changing things, make sure you click the 'Save As Default' button on the bottom of the panel. If you want to switch it back, you can always just go back into 'User Preferences' and press the 'Left arrow' button next to the rule you changed.  You can also restore all of the defaults by pressing the 'Restore' button next to the tree node you have edited.


-H

Wednesday, May 18, 2011

How to 'Verify using a different method" on Google's Webmaster Tools Home Page

So the folks over at Google haven't updated their guide to verifying your website in a while.  A quick search yields posts by angry 'webmasters' unable to find this mythical homepage from as early as 2009. A more recent example from 1/18/11 pretty much sums up the typical user experience with this problem.

Problem Statement:
You own a website, have it registered and hosted by some DNS agency and webhost, respecively.  In order to improve your website's page rank on Goolge, you have read their handy Search Engine Optimization guides here:(pdf file) and here:(webpage).  Unfortunately for whatever reason you were unable to verify your site with Google on the first try, and had to do something else away from your computer. Not being a quitter, you decided to give it another go a bit later.  But ALAS! All of Google's instructions for verifying tell you to go to the 'Webmaster Tools homepage' and click on the 'Verify' link next to the site you wish to verify.  But that is very difficult now since you aren't exactly sure what/where the 'Webmaster Tools homepage' is.  To complicate things even further, that 'Verify' link doesn't seem to exist.

SOLUTION:
If you haven't done so yet, log in to your Google account.
AHA! There are my sites! But wait, there isn't a link next to them that says 'Verify' ... the only things next to my URL's are a check-box and a drop-down selector with entries for 'Add or remove owners' and 'Google Analytics profile'.
*hmm...?*
Click on the drop-down selector and choose 'Add or remove owners'.  The page should reload and after that ...
VOILA! You should now be able to see a link smack in the middle of the page that reads "Verify using a different method".

I only post this because it just took me half an hour to figure that out <)
Oh, and to anyone that finds this helpful, you're welcome!  ;)

-H

First post, w00t!

First of all yes, I am allowed to use the declamation 'w00t!' being both a Computer Scientist and [former] DnD geek. I currently plan to use this soap box for many things: track the progress of my company's up-and-coming video game release, educate others via some (hopefully) well-written tutorials, show off my artistic talents, rant, ramble, and generally anything I happen to think of in the near-to-far future.

Welcome aboard me hearties, you're in for a wild ride!

-H