One of the video games being made in class needs to determine where the user clicks. Instead of creating a MouseClick event it makes sense to incorporate this into our GameTimer_Tick event. This is the code we came up with to test.
We added a Global Variable called Previousmbs which is the data type MouseButtonState. We initialized it to MouseButtonState.Released.
The if statement checks if the Mouse.LeftButton was released AND whether the Previousmbs was pressed (this allows the code to only run once and not all the time the user is not pressing the button). In my example I am removing all the items from the Canvas just to make it really visually obvious that the if statement ran. You probably don’t want to do that!
I also have a line that modifies the title so you can see the coordinates where the mouse was clicked – you can use the coordinates to determine if there is an object on the canvas in the same location.
After the if statement is done I want to ensure that the Previousmbs is reset every time the timer ticks so that my if statement is accurate.