Im making a small "physics" app that accelerates a picture box, and then deaccelerate it until it stops. I have the acceleration working, but the deacceleration is giving me problems:
Code:// Accelerate private void timer1_Tick(object sender, EventArgs e) { cmdStartStop.Text = "Stop Simulation"; box.Left += x; velocity += acceleration; x += velocity; lblPos.Text = "Position: " + x; lblVel.Text = "Velocity: " + velocity; lblAcc.Text = "Acceleration: " + acceleration; }I start and stop the simulation with a button.Code:private void timer2_Tick(object sender, EventArgs e) // Deaccelerate { while (velocity > 0) { box.Left += x; velocity -= acceleration; x += velocity; lblPos.Text = "Position: " + x; lblVel.Text = "Velocity: " + velocity; lblAcc.Text = "Acceleration: " + acceleration; } }
timer2 is disabled at load
button activates timer1
button then deactivate timer1 and activate timer2




Reply With Quote