I have a problem that not all inputs of my mouse events seem to be registered. The update logic is checking a 2 dimensional array of 10x10 . It's logic for a jewel matching game. So when i switch my jewel I can't click on another jewel for like half a second. I tested it with a click counter variable and it doesn't hit the debugger when i click the second time after the jewel switch. Only if I do the second click after waiting half a second longer. Could it be that the update logic is too heavy that while he is executing update logic my click is happening and he doesn't register it?
What am I not seeing here :)? Or doing wrong. It is my first game.
UPDATE :
I changed to Variable time step, then i saw after the reindex of my jewels (so after the switch) i see the elapsedgametime was 380ms. So I guess that is why he doesn't catch the short "Press" of my mouseclick because update method is still busy with executing the reindexing code. Anyone knows how I can deal with this .. Or do I have to start using threads because my update of reindex takes too long?
SOLVED : The problem was that in my reindexing code I got out of bound exceptions which I catched and then continued. That catching of exceptions caused a massive lag each time a reindex happened. Now everything runs smoothly and I do not have to worry about a slow Update. But I'm still asking the question.. what should you do If you have really heave update logic where the time to process the logic takes almost a 0.5 second? I guess you need to execute your game logic in multiple threads to reduce the update time? I'm also thinking i'll never have to worry about this for a jewels game :p. It's more for a problem for a heavy physics game with alot of game objects ?
My function of the update methode looks like this.
public void UpdateBoard()
{
currentMouseState = Mouse.GetState();
if (currentMouseState.LeftButton == ButtonState.Pressed &&
prevMouseState.LeftButton != ButtonState.Pressed)
{
debugCount++;
if (debugCount == 3)
{
int a = 4;
}
leftButtonPressed = true;
}
if (this.IsBoardActive() == false)
{
UpdatingLogic = true;
if (leftButtonPressed == true)
{
// this.CheckDropJewels(currentMouseState);
this.CheckForSwitch(currentMouseState);
if (SwitchFound == true)
{
reIndexSwitchedJewels = true;
}
this.MarkJewel(currentMouseState);
}
if (CheckForMatches == true)
{
if (this.CheckMatches(5) == true)
{
this.RemoveMatches();
reIndexMissingJewels = true;
}
else
{
CheckForMatches = false;
}
}
UpdatingLogic = false;
if (currentMouseState.RightButton == ButtonState.Pressed &&
prevMouseState.RightButton != ButtonState.Pressed)
{
this.CheckMatches(5);
}
this.ReIndex();
leftButtonPressed = false;
}
prevMouseState = currentMouseState;
this.UpdateJewels();
}
prevMouseState
is a property of the class, butcurrentMouseState
is created in the function stack? Any specific reason for that? And (related) are you certain thatprevMouseState
is always valid when you use it in your if statement? – Seth Battin Oct 31 '13 at 15:49