Game Development Reference
In-Depth Information
TaoFramework\lib directory, and choose Tao.Sdl.dll ). Another dll also needs
to be copied to the bin directories— sdl.dll . We'll go through the various
controls one by one and then finally build up a fully supported controller. If you're
not using an Xbox 360 controller, you should still be able to follow this section
with any other controller. Just substitute the controls used where necessary.
The controller is the main way that the player interacts with the game. For that
reason we always want to know the current state of the controller. Every frame
will include code that asks the controller the state of all its controls, and we'll
update our representation in memory. The constant querying of a device is
sometimes known as polling.
The SDL library requires its joypad subsystem to be initiated before it can be
used. For now this code can be placed in the InputTestState , but it will
eventually need to be moved to the input class.
bool _useJoystick = false;
public InputTestState()
{
Sdl.SDL_InitSubSystem(Sdl.SDL_INIT_JOYSTICK);
if (Sdl.SDL_NumJoysticks() > 0)
{
// Start using the joystick code
_useJoystick = true;
}
}
The setup code is quite readable. The joystick subsystem of SDL is initiated, and
if it works, then we can use joysticks. Next in the engine library project, a class
needs to be made to represent the controller. Because a very specific controller is
going to be represented, I'm going to call this class XboxController .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.Sdl;
namespace Engine
{
public class XboxController : IDisposable
 
Search WWH ::




Custom Search