I'm moving 3d camera like this:
Point3DAnimation pa;
// Triggered by user click
void MoveCamera(object sender, EventArgs e)
{
pa = new Point3DAnimation(myPoint3D, TimeSpan.FromMilliseconds(2000));
pa.Completed += new EventHandler(pa_Completed);
Camera.BeginAnimation(PerspectiveCamera.PositionProperty, pa); // anim#1
}
// we're in place. do some idle animation
void pa_Completed(object sender, EventArgs e)
{
pa = new Point3DAnimation(myPoint3Ddz, TimeSpan.FromMilliseconds(5000));
Camera.BeginAnimation(PerspectiveCamera.PositionProperty, pa); // anim#2
}
- User clicks.
- Camera moves to choosen position (anim#1).
- When anim#1 ends anim#2 is played.
Everything is ok... until user triggers MoveCamera when previous anim#1 is not finished.
In that case:
- New anim#1 is starting.
- Completed event of old anim#1 is triggered.
- anim#2 is started instatntly (overlapping new anim#1).
2 & 3 are wrong here. How i can avoid that?
I think that pa_Completed() should detect that new anim#1 is already playing, or MoveCamera() should unregister Complete event from old anim#1. But what the right way to do it?