Hey guys/gals, I've got a canvas that's 800x600 inside a window that's 300x300. When I press a certain key, I want it the canvas to move in that direction.
I've done this inside the window's code behind:
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
Key keyPressed = e.Key;
if (keyPressed == Key.W)
{
gcY += 5;
}
if (keyPressed == Key.S)
{
gcY -= 5;
}
if (keyPressed == Key.A)
{
gcX += 5;
}
if (keyPressed == Key.D)
{
gcX -= 5;
}
gameCanvas.RenderTransform = new TranslateTransform(gcX, gcY);
}
Well, it works, but the movement is jerky. And if I hold on to a key, W for instance, then it pauses for a split second, before moving. Is there anyway to make the movement smoother and to get rid of the pause when you hold down a key? Thanks.