Archive

Archive for August, 2013

Tetris: Adding gamepad support

August 30, 2013 4 comments

In this article, we will look at how to add gamepad support to a game using our Tetris clone as an example.

Simple2D 1.11 includes gamepad support using XInput – the new replacement for DirectInput in DirectX 11 – and makes it ridiculously easy to add support to existing games as we shall see here. If you would rather code everything yourself and want the nitty gritty, check out my 2-part mini-series XInput Tutorial: Adding gamepad support to your Windows game for the low-level details.

Download (SimpleTetris 1.5): Source code | Executable

Read more…

XInput Tutorial Part 2: Mapping gamepad buttons and analog movement to Windows keyboard events

August 30, 2013 13 comments

In part 1 of this mini-series we looked at the basics of the XInput API and how to read the state of all the analog and digital buttons on a gamepad, then wrapped it up into a simple Gamepad class. In this article, we shall look at how to translate button pushes and analog stick/trigger movements into Windows keyboard events for those applications which use the Windows messages WM_KEYDOWN and WM_KEYUP to handle user keyboard input.

The problem

XInput requires you to poll the controller each frame to get changes in state. If you currently use a function like GetAsyncKeyState() to check for keyboard key presses in your game, this is fine, but if you are using the Windows keyboard messages WM_KEYDOWN and WM_KEYUP, this will not fit in with your current model, and the game will require a bit of re-engineering to handle polling as well. Ideally, we would like to avoid this and just funnel controller movements and button presses through WM_KEYDOWN and WM_KEYUP as if they were normal keyboard key presses.

To do this, we will expand upon our basic Gamepad class to include keyboard mapping and event dispatch functions.

NOTE: If you can’t be bothered with the low-level details and just want to shoehorn gamepad support into a game really quickly, my Simple2D library (version 1.11 and above) includes gamepad support – see the Tetris gamepad support article for a quick example on how to use the library to add gamepad support in just a few minutes! Read more…

XInput Tutorial Part 1: Adding gamepad support to your Windows game

August 30, 2013 7 comments

In this game development tutorial we will look at how to add support for gamepads to Windows games written in C++, using the XInput API introduced in DirectX 11. XInput replaces DirectInput from previous DirectX versions and greatly simplifies the task of working with game controllers, as long as they are XInput-compatible. If you don’t normally use a gamepad on your PC but you own an Xbox 360 then you’re in luck: Xbox 360 controllers support XInput, so just plug it into a USB port on your PC and you’re good to go.

Our end goal is to develop a library which allows us to shoehorn in gamepad support to existing games which use the keyboard and mouse for input with almost no extra effort at all (and if you want to cut to the chase and just use such a library, my Simple2D library versions 1.11 and above include all the code in this article and more to do the job for you), To start with though, we’ll have a quick crash course on the basic API.

In this article, you will learn:

  • How to compile applications which use XInput
  • How to check if a controller is connected and on which port
  • How to check for digital button presses
  • How to check the movement positions of the analog thumb sticks and rear triggers
  • How to calibrate deadzones for the analog sticks
  • How to make a class which wraps it all together

NOTE: If you can’t be bothered with the low-level details and just want to shoehorn gamepad support into a game really quickly, my Simple2D library (version 1.11 and above) includes gamepad support – see the Tetris gamepad support article for a quick example on how to use the library to add gamepad support in just a few minutes!

Read more…

LightSwitch for Games Part 2: OData Tutorial and User Account Management on the Server

August 29, 2013 5 comments

NOTE: Although this series is aimed at small game developers, it is equally applicable to anyone wishing to learn how to use LightSwitch.

In part 1 of this series we looked at the rationale for using LightSwitch as a game data server and how to setup and publish a LightSwitch project on Windows Azure (optional). In this part, we’ll look at the server-side work needed to enable users to create their own accounts on the game network. We shall take a look at several client-side samples for registering and logging on in part 3 to complete the end-to-end process.

In this article, you will learn:

  • What OData is, how it works and the underlying HTTP messages it uses
  • How to use OData to retrieve and insert rows in your LightSwitch application database
  • How users, permissions and roles are organized in a LightSwitch application
  • How to create a desktop application to edit the users and roles in your application
  • How to create a WCF RIA Service which provides an updateable view of two tables
  • How to create an anonymous guest user with limited permissions (in this case, permission to add a new, real user)
  • How to limit a user to accessing only their own data in a particular table
  • How to create a user profiles table which can store additional information and automatically generates a new user in LightSwitch’s internal user authentication database when a new row (user) is inserted
  • How to automatically assign new users to roles

This article assumes some familiarity with:

  • HTTP (GET and POST methods, headers and request and response bodies)
  • a basic understanding of either XML or JSON
  • a basic understanding simple database structures (tables and rows) and basic SQL queries (SELECT and INSERT)
  • a moderate understanding of C# (but you can just copy and paste the code if you aren’t too familiar with C#)

NOTE: You need Visual Studio Professional 2012 Update 2 or Update 3, or Visual Studio 2013 (Preview) to complete the tutorials in this article. Note that in Visual Studio 2013 (Preview), the organization of items in Solution Explorer has changed so some items may be in different places to those indicated below. Read more…

Simple2D 1.11 now available

August 29, 2013 9 comments

A new major release of Simple2D is now available (the download link can be found at the bottom of the page).

Version 1.11 introduces 49 improvements and bug fixes with an emphasis on user interface coding. Improvements have been made to scene objects, user interface objects and object groups, experimental support for skinning has been added, as well as support for XInput-compatible gamepads. Read more…

C# DirectX API Face-off: SlimDX vs SharpDX – Which should you choose?

August 24, 2013 22 comments

A question I often see asked by beginning game programmers on the internet is:

I want to code my game in C#. Which DirectX wrapper API should I use?

As with most such things, all choices have their pros and cons. Here I will look at the two frameworks most currently in use at the time of writing: SlimDX and SharpDX. Read more…

Categories: DirectX Tags: , , , , ,

Visual Studio 2013 Preview: Get rid of the all-caps menu bars

August 23, 2013 5 comments

I don’t believe it. The Visual Studio 2013 Preview build still uses all-caps menu bars.

That just won’t do. To eliminate this UI design monstrosity from your desktop, open Windows PowerShell (if you don’t know how to do this, open a command prompt, type powershell and press Enter), and type:

Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\12.0\General -Name SuppressUppercaseConversion -Type DWord -Value 1

(all on one line)

Then restart Visual Studio. Your menus will no longer be shouting at you.

You’re welcome.

 

%d bloggers like this: