Game Development Reference
In-Depth Information
certain threshold. The part that is ignored is known as the dead zone and can
vary from controller to controller (for this reason it's best to be a little generous
when specifying your dead zone).
The control stick is treated as two axes—an X axis from left to right and a Y axis
from top to bottom. SDL returns the axis information as short number value
but a more convenient representation would be a float from 1 to 1. The 1
value is the control stick pushed far to the left (or down) and 1 would be fully
pushed in the opposite direction.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.Sdl;
namespace Engine
{
public class ControlStick
{
IntPtr _joystick;
int _axisIdX = 0;
int _axisIdY = 0;
float _deadZone = 0.2f;
public float X { get; private set; }
public float Y { get; private set; }
public ControlStick(IntPtr joystick, int axisIdX, int axisIdY)
{
_joystick = joystick;
_axisIdX = axisIdX;
_axisIdY = axisIdY;
}
public void Update()
{
X = MapMinusOneToOne(Sdl.SDL_JoystickGetAxis(_joystick,
_axisIdX));
Y = MapMinusOneToOne(Sdl.SDL_JoystickGetAxis(_joystick,
_axisIdY));
}
Search WWH ::




Custom Search