300x300 のウィンドウ内に 800x600 のキャンバスがあります。特定のキーを押すと、キャンバスがその方向に移動するようにします。
ウィンドウのコードビハインド内でこれを行いました:
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
キー 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);
}
動作はしますが、動きがガクガクします。たとえば、キーを押したままにすると、W移動する前に一瞬停止します。
動きをよりスムーズにし、キーを押したときの一時停止をなくす方法はありますか?
ありがとう。