Game Development Reference
In-Depth Information
The Mouse class isn't constructed in the Input class because the Input class
shouldn't have to know about the form or simple OpenGL control; instead, the
mouse object is constructed in the form.cs constructor.
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
_input.Mouse = new Mouse(this, simpleOpenGlControl1);
Now that the Mouse class exists, the UpdateInput function in the form class
can be simplified.
private void GameLoop(double elapsedTime)
{
UpdateInput(elapsedTime);
_system.Update(elapsedTime);
_system.Render();
simpleOpenGlControl1.Refresh();
}
private void UpdateInput(double elapsedTime)
{
// Previous mouse code removed.
_input.Update(elapsedTime);
}
The elapsedTime is passed from the main GameLoop method into the Up-
dateInput method.
The elapsedTime has been passed to both the UpdateInput and Update
functions in case we ever want the mouse to support a hover event. For instance,
in a real-time strategy game, you might hover the mouse over a unit for a second
or two, and on detecting that hover behavior, the game might pop up a tool tip
displaying the unit's name and stats.
The mouse buttons can be treated in the same way as the controller buttons. The
button will have Held and Pressed members. For the mouse, the state of the
Pressed member corresponds to a Windows Forms click event. The gamepad
works by polling, which means every frame the program queries the gamepad to
find out what buttons are pressed and where the control sticks are. The mouse
 
Search WWH ::




Custom Search