Game Development Reference
In-Depth Information
If you press Enter + Alt , nothing will happen at the moment. As mentioned in the pre-
vious chapter, we can't toggle fullscreen mode yet since we are not using DirectX's
graphics APIs yet. Application Programming Interface ( API ) simply refers collect-
ively to all of the public methods and types that are made available by the API. For
example, SlimDX is an API, as is DirectX.
Smaller parts of an API can sometimes be considered as APIs in their own right as
well. For example, DirectX's DirectInput is an API in and of itself. DirectX is more like
a collection of several different APIs for different purposes, as is SlimDX.
As you can see, keyboard input is fairly simple to implement with SlimDX. Mouse in-
put, though we haven't really used any yet, is just as simple. Responding to mouse
input is almost identical to doing so for keyboard input. Simply check the X and Y
properties of the MouseState object to find out the mouse cursor's position. The Z
property allows you to detect movement of the mouse's scroll wheel if it has one. If
your mouse does not have a scroll wheel, then this property will simply return 0 . Note
that the value of the Z property is a delta, or in other words it is the amount that the
scroll wheel has moved since the last update. Lastly, you can use the IsPressed()
and IsReleased() methods to detect if a given mouse button is pressed or re-
leased.
Note that the downloadable code for this chapter also includes mouse handling
methods added into our UserInput class. These are IsMouseBut-
tonPressed() , IsMouseButtonReleased() , IsMouseButtonHeldDown() ,
MouseHasMoved() , and MousePosition() , among others. The IsMouseBut-
tonHeld() method can be used to implement clicking-and-dragging behavior while
the HasMouseMoved() methodreturns true ifthemousehasmovedsincethepre-
vious frame, or false otherwise.
Search WWH ::




Custom Search