Game Development Reference
In-Depth Information
public ControlTrigger LeftTrigger { get; private set; }
// in the constructor
RightTrigger = new ControlTrigger(_joystick, 2, false);
LeftTrigger = new ControlTrigger(_joystick, 2, true);
// in the update function
RightTrigger.Update();
LeftTrigger.Update();
These triggers can be visualized very simply; two more points are rendered, each
representing one of the triggers. The more the trigger is pressed, the further the
point moves. The colors are slightly different so that they can be distinguished
from the control sticks. This code should be added to the test state near the
button and control stick visualizations but between the glBegin and glEnd
statements.
Gl.glColor3f(0.5f, 0, 0);
Gl.glVertex2f(50, _controller.LeftTrigger.Value * 300);
Gl.glColor3f(0, 0.5f, 0);
Gl.glVertex2f(-50, _controller.RightTrigger.Value * 300);
The final control to be added is the D-pad. The D-pad will be treated as four
buttons: up, down, left, and right.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.Sdl;
namespace Engine
{
public class DPad
{
IntPtr _joystick;
int _index;
public bool LeftHeld { get; private set; }
public bool RightHeld { get; private set; }
public bool UpHeld { get; private set; }
public bool DownHeld { get; private set; }
public DPad(IntPtr joystick, int index)
 
Search WWH ::




Custom Search