First off I'm somewhat new to C# but I'm working on a game in C# Monogame and I'm trying to get timers working. There was a similar question answered around here a while back but I found that the solution doesn't work for me, perhaps an older version or I'm missing something, so I wrote similar timer and timer manager classes myself.
I ended up with a wait(time)
function (that seems to work from looking through the debugger but not sure) now I'm wondering how can I get an action to be executed when the timer created by that expires.
Ideally I'd like something like
timerManager.Wait(10)
{
//do stuff once done waiting
}
Here's my timer classes - Timer.cs and TimerManager.cs
TimerManager gets instantiated in my player class and wait is called in the update function by keyboard input.
if(keyState.IsKeyDown(Keys.Space))
{
if(canJump)
{
vAccel = jumpSpeed * -1;
stripManager.setCurrentAction(PlayerActions.jump);
timerManager.Wait(1);
}
}
So my question is how can I get an action to trigger, ideally with a set of {} as shown above. I'm aiming to having a class I can reuse for any sort of delay I need in my game.
No comments:
Post a Comment