Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Phone

Windows Phone 7 : Running XNA Projects in Windows (part 3) - Input Differences, Isolated Storage, Application Life Cycle

6/24/2013 11:23:15 AM

5. Input Differences

The majority of Windows users will not have access to a touch screen, but the mouse can be used to provide most of the interaction that the touch screen can provide. The loss of multitouch input is offset by having multiple mouse buttons, and the mouse wheel available to most users.

On the other hand, all your users will have keyboards, whereas only a minority of Windows Phone 7 users will have this hardware available.

This section explores the differences in input methods between the two environments.

5.1. Mouse Input

When we wanted to read raw touch input from the screen in our Windows Phone 7 projects, we used the TouchPanel class . The TouchPanel class is available when running on Windows so the code still compiles, but unless you have a capable touch-screen monitor running under Windows 7, it reports a MaximumTouchCount of 0 and never returns anything from its GetState function.

Assuming that we decide to use mouse input as an alternative to touch input, the best way to obtain this data in a Windows game is by using the Mouse class.

This class contains a static method named GetState that returns a MouseState object containing all sorts of details about the mouse. These include the following:

  • The mouse position relative to the window, using the X and Y properties. This will be available regardless of which mouse buttons are pressed, and at all times, even if the mouse cursor is outside the game window.

  • The state of the LeftButton, MiddleButton, and RightButton. The available state values are Released when the button is up, and Pressed when it is down.

  • Support for the state of two additional mouse buttons via the XButton1 and XButton2 properties (though many mice will not have sufficient buttons to support this, and exactly which buttons they correspond to will vary from one mouse to the next).

  • A ScrollWheelValue that contains the cumulative distance that the mouse wheel has been scrolled. This is not incremented or decremented by values of 1, but uses larger values (typically 120 for each unit that the wheel is scrolled).

The capabilities are very different from the multitouch values that the TouchPanel class provides, and if your game is doing anything more complex than simple single-point interaction, you might need to invest some thought and time into remapping the control mechanism into the Windows environment.

The Mouse class is available and functional inside the Windows Phone 7 environment, too, so if its capabilities are suitable, you might be able to use the same code in both places. Windows Phone 7 treats the primary contact point as if it were the left mouse button.

There are several useful TouchPanel features that you will lose as a result of using Mouse on the device, however, as they are not offered by the MouseState class. They include the ability to tell whether the touch state is Pressed, Moved, or Released; and the TryGetPreviousLocation method. Also note that the X and Y position properties will always return the last known position unless contact is currently being made with the phone's screen.

5.2. Gestures

The high-level TouchPanel gestures are not supported in the Windows environment. The code will compile and run without any problems, but no gestures will be returned by the IsGestureAvailable or ReadGesture class members.

5.3. Keyboard Input

Now for a little good news: keyboard input is handled exactly the same way in Windows as it is in Windows Phone 7. The Keyboard.GetState function is used to return information about keys that are pressed, and the data is formatted just the same as on the phone.

5.4. GamePad Input

Windows games have an input mechanism that Windows Phone 7 does not, however, and that is the ability to use Xbox 360 game controllers for input. Input from these controllers is provided using the GamePad class.

Data is obtained by calling the static GamePad.GetState function, which is called passing in the index of the player whose gamepad values are to be returned. For single-player games, just pass PlayerIndex.One. The function returns a GamePadState object.

The first thing you need to do with this returned object is check whether it is actually receiving data from a connected gamepad. Its IsConnected property will return this piece of information; if it returns false, the rest of the state object will be entirely empty and another input mechanism must be sought.

If the device is connected, it offers a wealth of controller information:

  • The Buttons property returns a GamePadButtons object, which in turn has properties to allow the state of each individual button to be checked. These button properties are A, B, Back, BigButton, LeftShoulder, LeftStick, RightShoulder, RightStick, Start, X, and Y. That should be enough buttons for anyone.

  • The DPad property returns a GamePadDPad object, with properties to query the state of the directional pad: Down, Left, Right, and Up.

  • The ThumbSticks property returns a GamePadThumbSticks object, with properties for the controller's thumb sticks. Two properties are available, Left and Right, corresponding to the left and right stick. They each return a Vector2, allowing proportional values to be read rather than simple pressed or released values.

  • The Triggers property returns a GamePadTriggers object, allowing the state of the trigger buttons to be read. They are obtained from the Left and Right properties, and are once again proportional values, returned as a float.

The class also offers two methods, IsButtonDown and IsButtonUp, which allow a specific button's state to be checked. This will sometimes be more useful than the GamePadButtons properties, as passing the button as a parameter allows it to be easily reassigned by the player.

NOTE

The GamePad class will compile in the Windows Phone 7 environment, and in fact is used in all XNA projects to check for the state of the Back button. This is the only button that will return any values on the device, however.

6. Isolated Storage

Unlike Windows Phone 7, Windows is an open operating system and allows full access to its underlying file system. There is therefore no concept of isolated storage when running in Windows.

File access is instead performed using the normal System.IO namespace, exactly as it would be in another game.

XNA games in Windows also have no access to the IsolatedStorageSettings class that we used in the game framework to save and reload our game settings. This was a very useful class to have around, and we will need to replicate its behavior when running in Windows – this issue will be addressed in a moment.

7. Application Life Cycle

Windows is a fully multitasking operating system with none of the memory or processing constraints that the phone has to work within, so it does not have any concept similar to that of tombstoning.

When a Windows application is put into the background, it continues running exactly as it would have in the foreground. There is no need to maintain application state when the game deactivates or to perform any other similar processing.

Other -----------------
- Windows Phone 8 : Developing for the Phone - The Phone Experience (part 4) - Understanding Idle Detection, The Tilt Effect
- Windows Phone 8 : Developing for the Phone - The Phone Experience (part 3) - Application Client Area, Application Bar
- Windows Phone 8 : Developing for the Phone - The Phone Experience (part 2) - Designing for Touch
- Windows Phone 8 : Developing for the Phone - The Phone Experience (part 1) - Orientation
- Windows Phone 8 : Developing for the Phone - Application Lifecycle (part 3) - Tombstoning
- Windows Phone 8 : Developing for the Phone - Application Lifecycle (part 2) - Navigation
- Windows Phone 8 : Developing for the Phone - Application Lifecycle (part 1)
- Windows Phone 8 : Designing for the Phone - Implementing the Look and Feel of the Phone
- Windows Phone 8 : Designing for the Phone - Designing with Visual Studio
- Windows Phone 7 : 3D Game Development (part 4) - Rendering 3D Models
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro