Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

With the proliferation of touch based devices, many lacking a true D-Pad, I'm wondering if anyone has any resources on how to emulate a D-Pad on a touch screen? I'm specifically interested in XNA and/or Android code examples.

share|improve this question

6 Answers 6

up vote 5 down vote accepted

There is an XNA sample of touch thumbsticks here

I would reiterate that a dpad is unlikely to be the right interface for a touch screen like device.

Something like what epic has done with Infinity Blade for the iPhone may give you inspiration Movie Link

share|improve this answer
    
For future visitors, the link above now 404s. The example can now be found here: xbox.create.msdn.com/en-US/sample/touchthumbsticks –  Gabriel Isenberg Feb 8 at 6:54

Can I discourage you from attempting to emulate a D-pad on a touchscreen device?

The problems with emulating a D-pad on a touch screen are:

  • the D-pad takes up screen space that you could be using for the game;
  • unlike a real D-pad, an emulated D-pad offers almost no feedback: as a player, you can't tell which direction you're pressing in, neither by feel nor by sight (since your finger is covering up the D-pad on the screen). So your finger all too easily slips off the D-pad, or onto the wrong part of it, leading to fumbles and frustration.

A touchscreen device is much more than a device "lacking a true D-pad", as you put it. A touchscreen device allows the player to touch anywhere on the screen and so interact with any visible game element. This gives a wide range of game design possibilities, and these designs are likely to be much more pleasant to use than an emulated D-pad.

share|improve this answer
1  
Also, implementing Pathing for a small screen like that is trivial. Zoom and scroll the game map, then Tap and path! –  Stephen Furlani Nov 10 '10 at 15:08

I know this isn't the most useful answer, but unless you are porting a project over from another platform, I'd suggest reconsidering on the virtual D-Pad. Most implementations of virtual D-Pads have been poor at best, the lack of tactile feedback make them a poor choice for the platform.

You are far better off looking at building an interface to your game that highlights the platforms strengths instead of building to the platforms weakness.

share|improve this answer
    
Apparently Gareth answered the same way as I was typing that. Nothing to see here... move along. –  wkerslake Nov 9 '10 at 23:48
    
Glad to see I'm not alone on this! –  Gareth Rees Nov 9 '10 at 23:51

Like the others have said, it's best to come up with a design that fits the environment, not force the environment to fit your design, but if you do stick with the D-Pad, here's how you might do it:

If you think of the "touch point" as a mouse cursor, you are basically create a "hot spot" that reacts to the cursor movement.

The best/simplest way to do it I think is to make a semi-transparent(remember, you are covering the game screen) box or circle in one of the bottom corners, where the player is most likely to have their finger already. Then you just track the position of the player's finger relative to the center of the hot spot, and that's your input delta value.

share|improve this answer
    
This is the way most games solve the d-pad controller problem it seems. It sucks for precision platforming though. –  Nailer Nov 10 '10 at 9:54

I see most people here thinks a D-Pad is a bad idea, and they are right - most of the time. Dungeon Hunter from Gameloft for Android is a great example of a great D-Pad for touch-screens. It is responsive, have a 360 degree direction, an is not "dumb". What I mean that it is not "dumb", is that when you press the D-Pad and slide you finger out from the D-Pad area, it doesn't interfare with what happens on the screen - it just extends. So if you accidentaly slip out of the D-Pad area you won't loose movement.

I think 360 degree direction and out-of-bounds responsivness is important and if you can do that you will have a chance in doing the D-Pad right.

share|improve this answer

If you want to implement a D-Pad, the easiest way that comes to my head is to create four rectangles (one for each direction of the D-Pad) and then check if the touch location is within the bounds of any of the rectangles.

As the other guys said; think twice before implementing a D-Pad on a touch screen. On the other hand I´ve seen people playing those GBA emulators all day on their iPhones.

It´s up to you ... can you tell us what are you planning to do that involves a simulated D-Pad?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.