我正在使用计时器来动画对象以恒定速度行进。
这是我的代码:
Class class1 = new Class();
public int x;
public int y;
public Form1()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
class1.Draw(g);
}
private void timer1_Tick(object sender, EventArgs e)
{
x += 1;
class1.Move(x/2, x/2);
Invalidate();
}
班级:
class Class
{
private int x;
private int y;
public void Draw(Graphics g)
{
SolidBrush Brush = new SolidBrush(Color.White);
g.FillRectangle(Brush, x, y, 10, 10);
}
public void Move(int X, int Y)
{
x = x + X/3;
y = y + Y/3;
}
}
广场正在加速,有什么想法可以让它匀速行驶吗?