2个回答
展开全部
有用游戏框架吗?单纯的C#代码的实现性能比较差。可以看看XNA的资料。如果只是用C#的基本都是通过修改Location的方法来做的。如下是代码片段供你参考(假设窗体中已有一个PictureBox):
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.W:
this.pictureBox1.Top -= 3;
break;
case Keys.S:
this.pictureBox1.Top += 3;
break;
case Keys.A:
this.pictureBox1.Left -= 3;
break;
case Keys.D:
this.pictureBox1.Left += 3;
break;
default:
break;
}
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.W:
this.pictureBox1.Top -= 3;
break;
case Keys.S:
this.pictureBox1.Top += 3;
break;
case Keys.A:
this.pictureBox1.Left -= 3;
break;
case Keys.D:
this.pictureBox1.Left += 3;
break;
default:
break;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询