Skip to Main Content
Learning XNA 3.0
book

Learning XNA 3.0

by Aaron Reed
November 2008
Beginner content levelBeginner
510 pages
16h 24m
English
O'Reilly Media, Inc.
Content preview from Learning XNA 3.0

Mouse Input

XNA provides a Mouse class to interact with the mouse that behaves very similarly to the Keyboard class. The Mouse class also has a GetState method that you can use to get data from the mouse in the form of a MouseState struct. The Mouse class also has another method worthy of note: void SetPosition(int x, int y). This method will—you guessed it—allow you to set the position of the mouse. This position is relative to the upper-left corner of the game window.

The MouseState struct has several properties that will help you understand what is happening with the mouse at the particular moment in time when you called GetState. These properties are detailed in Table 3-2.

Table 3-2. Important properties of the MouseState struct

Property

Type

Description

LeftButton

ButtonState

Returns the state of the left mouse button.

MiddleButton

ButtonState

Returns the state of the middle mouse button.

RightButton

ButtonState

Returns the state of the right mouse button.

ScrollWheelValue

int

Returns the total accumulated movement of the scroll wheel since the game started. To find out how much the scroll wheel has moved, compare this value to the previous frame's scroll wheel value.

X

int

Returns the value of the horizontal position of the mouse in relation to the upper-left corner of the game window. If the mouse is to the left of the game window, the value is negative. If the mouse is to the right of the game window, the value is greater than the width ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning XNA 4.0

Learning XNA 4.0

Aaron Reed
Beginning C# 7 Programming with Visual Studio 2017

Beginning C# 7 Programming with Visual Studio 2017

Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid

Publisher Resources

ISBN: 9780596154905Supplemental ContentErrata Page