Game Development Community

xBox 360 Controller Support in 2D and 3D

by Tony Pitman · in Torque X 2D · 06/01/2009 (5:20 pm) · 2 replies

I have written a couple of CC games just using the basic XNA stuff and no engine other than starting with the starter game and writing all the code myself. I am looking into using TorqueX for my next game.

In the games that I have done without Torque X 2D I first start with a screen the shows the basic instructions and then asks the user to press A to start the game or B to exit. All of my games so far are single user games.

What I do next in my code is watch for the press of A and when the user does that I see which controller (1-4) pressed the A and that becomes the controller that everything I do depends on.

If my game is in trial mode then I add a Buy Now button to my menu. I also check to see if the controller that is being used has what it needs to purchase the game. If it doesn't then I don't add the buy now button.

I would like to know what similar functionality is available in the Torque X stuff.

#1
06/02/2009 (2:33 pm)
You can use raw XNA code in Torque X without any problems. In fact, as far as I know, you will have to as some of the XBox360 specific stuff (like determining if it is a trial game and whatnot) are not a part of Torque X.

For my start screen, I made keybinds for each player to allow them to move the cursor around the menu. When "Start Game" is selected, it determines which controller issued the command and activates that player. Torque X has a PlayerManager class that can be used to manage all four players by allowing you to add/remove data on the player (like score and lives), specify an input map (input maps are keybinds. You generally bind a move, which lets you receive a Move mapping with control stick positions, or bind an action, which binds a callback function to be executed if a button is pressed), specify the object the player is controlling, etc.

Then, once the game is started, I add keybinds to all the other players that aren't active, so if they press the A button, they can join in.

Basically, you will probably end up creating a component that, when the game is started, spawns the appropriate menus you want. The component can register for tick callbacks so it can periodically check the player state and take action if something changes.
#2
06/02/2009 (3:03 pm)
Thanks for the reply. Sounds like a place the GG could maybe provide a higher level component at some point, but I get the idea for now.