catch mouse click:
if (Mouse.GetState().LeftButton == ButtonState.Pressed) { i++; } And the fact is that i is added until I release the mouse button. Is it possible to somehow make this click one-time?
catch mouse click:
if (Mouse.GetState().LeftButton == ButtonState.Pressed) { i++; } And the fact is that i is added until I release the mouse button. Is it possible to somehow make this click one-time?
Sure you may. In fact, you are trying to catch the transition from the state of the button from "released" to "pressed". But for this you can not do without memorizing the previous state of the button:
private static MouseState mouse_prev; private static MouseState mouse_curr; And in your cycle should be something like this:
mouse_prev = mouse_curr; mouse_curr = Mouse.GetState(); if(mouse_prev.LeftButton == ButtonState.Released && mouse_curr.LeftButton == ButtonState.Pressed) { i++; } Source: https://ru.stackoverflow.com/questions/603264/
All Articles