Hi,
I am creating a game engine for WPF. I am trying to move away from DispatcherTimer to StopWatch, to get a more constant speed of the game (as DispatcherTimer skips turns if there are too many objects in the game).
I can write the code for updating the game correctly using a StopWatch (that is, my game objects' speeds and positions are calculated correctly), but when I omit the DispatcherTimer the GUI will never redraw.
I know there are several ways to force a redraw of the window, but what would be my best option for a 2D game in WPF? I'm just looking for something simple that works rather efficiently without a lot of hassle.
This is my current code for placing objects onscreen, many times per second:
for (int i = 0; i < Bodies.NumberOfBodies();
{
Body body = Bodies.Bodylist[i];
var shape = body.GetShape();
game.Children.Add(shape);
Canvas.SetLeft(shape, body.PosX - offsetX);
Canvas.SetTop(shape, body.PosY - offsetY);
}
Thanks!
Petter
What I have tried:
I have read up on the subject, but there are many solutions and I don't know what would be the most suitable.