【发布时间】:2019-05-06 09:55:40
【问题描述】:
返回错误
CS0029
C# 无法将类型“void”隐式转换为“System.EventHandler”
这里使用了那个函数:
gameTimer.Tick += UpdateScreen();
函数是:
private void UpdateScreen()
{
if(Settings.GameOver == true)
{
if (Input.KeyPressed(Keys.Enter))
{
StartGame();
}
}
else
{
if (Input.KeyPressed(Keys.Right) && Settings.direction != Direction.Left)
Settings.direction = Direction.Right;
else if (Input.KeyPressed(Keys.Left) && Settings.direction != Direction.Right)
Settings.direction = Direction.Left;
else if (Input.KeyPressed(Keys.Up) && Settings.direction != Direction.Down)
Settings.direction = Direction.Up;
else if (Input.KeyPressed(Keys.Down) && Settings.direction != Direction.Up)
Settings.direction = Direction.Down;
MovePlayer();
}
pbCanvas.Invalidate();
}
【问题讨论】:
-
UpdateScreen()是 执行 而UpdateScreen是 method 本身;正确的语法是gameTimer.Tick += UpdateScreen;。我们将Tick分配给方法,而不是分配给方法的result(即void)
标签: c#