Game Development Reference
In-Depth Information
Texture2D currentColor;
Finally, we need a variable for storing the origin of the ball:
Vector2 colorOrigin;
Now that we have our member variables in place, let us have a look at the
LoadContent method. In this method, we need to load a few extra sprites, and store
them in the member variables that we just declared:
colorRed = Content.Load<Texture2D>("spr_cannon_red");
colorGreen = Content.Load<Texture2D>("spr_cannon_green");
colorBlue = Content.Load<Texture2D>("spr_cannon_blue");
At the start of the program, we assume that the cannon is blue, so we assign the blue
sprite to the currentColor variable:
currentColor = colorBlue;
Finally, we calculate the origin of the ball sprite which we choose as its center:
colorOrigin = new Vector2(currentColor.Width, currentColor.Height) / 2;
6.5.3 Handling the Keyboard Input
For handling the keyboard input, we will need the keyboard state. For completeness,
we will store the previous and current state for both the keyboard and the mouse. so,
we need the following member variables:
MouseState currentMouseState, previousMouseState;
KeyboardState currentKeyboardState, previousKeyboardState;
When we enter the Update method, we have to first update all these member variables
so that they contain the right values when we are actually going to handle the player
input. We follow the same procedure for the keyboard states as for the mouse states:
previousMouseState = currentMouseState;
previousKeyboardState = currentKeyboardState;
currentMouseState = Mouse.GetState();
currentKeyboardState = Keyboard.GetState();
If we want to know if the player has pressed the 'R' key, we use both the current
and previous keyboard states, like we did with the mouse state:
Search WWH ::




Custom Search