This project is read-only.

All objects move to the same position

Apr 14, 2010 at 4:25 PM
Hey guys i am using the code below to randomly move multiple objects around. however when i run the code the objects get sent to the proper position the first time it is run but if i run it a secont time it all goes to the same coordinates please help. for (int i = 0; i < applications.Count; i++ ) { if (applications[i].app_name == name) { Random random = new Random(); int xpos = random.Next(80, 1200); int ypos = random.Next(150, 630); Canvas.SetZIndex(applications[i], i+20); Canvas.SetLeft(applications[i], Fall_Position); Canvas.SetTop(applications[i], 0); applications[i].Visibility = System.Windows.Visibility.Visible; applications[i].StartDownAnimation(1, ypos, 100); //p.SlideTo(xpos, ypos, 3, AnimationTransitions.CubicEaseOut, 0); //p.SlideTo(500, 0, 3, AnimationTransitions.CubicEaseOut, 8); Random random2 = new Random(); int xpos2 = random2.Next(80, 1200); int ypos2 = random2.Next(150, 630); var eog = new EaseObjectGroup(); var eox = ArtefactAnimator.AddEase(applications[i], AnimationTypes.X, xpos2, 1, AnimationTransitions.CubicEaseOut, 1); var eoy = ArtefactAnimator.AddEase(applications[i], AnimationTypes.Y, ypos2, 1, AnimationTransitions.CubicEaseOut, 1); eog.AddEaseObject(eox); eog.AddEaseObject(eoy); eoy.Complete += new EaseObjectHandler(AppData_Complete); //eox.OnComplete(Easeobject_Complete).OnUpdate(Easeobject_Complete).OnBegin(Easeobject_Complete); // applications[i].DimensionsTo(size, size, 3, AnimationTransitions.ElasticEaseOut, 0); //applications[i].SlideTo(xpos2, ypos2, 1, AnimationTransitions.CubicEaseOut, 1); // applications[i].RotateTo(_rnd.NextDouble() * 360, 1, AnimationTransitions.ElasticEaseOut, 0); } }
Apr 15, 2010 at 9:34 PM

First thing you should do is make sure you have the latest version (2.0.4.5) or greater. It fixes an int issue that might crop up because X and Y really want double values.

From what I understand of this code, there is an initial position of all applications, something triggers the Randomization of locations, and you want a callback of when they are all complete.

Does this help?

 

 

public double Fall_Position = 50;

private void INIT()
{
    var random = new Random(); 
    for ( var i = 0; i < applications.Count; i++ )
    {
        var xpos = random.Next(80, 1200);
        var ypos = random.Next(150, 630);

        // set application initial state
        Canvas.SetZIndex(applications[i], i+20);
        Canvas.SetLeft(applications[i], Fall_Position); 
        Canvas.SetTop(applications[i], 0);
        applications[i].Visibility = Visibility.Visible; 
    }

    // start animating positions
    Randomize();
}

private void Randomize()
{
    var random = new Random();

    // create one group listener for all animations
    var eog = new EaseObjectGroup();

    // triggered when the entire group has completed animations
    eog.Complete += new EaseObjectGroupCompleteHandler(EaseGroupComplete);

    // randomize locations
    for ( var i = 0; i < applications.Count; i++ )
    {
         var xpos = random.Next(80, 1200);
         var ypos = random.Next(150, 630);
         
         var eox = ArtefactAnimator.AddEase(applications[i], AnimationTypes.X, xpos, 1, AnimationTransitions.CubicEaseOut, 1);
         var eoy = ArtefactAnimator.AddEase(applications[i], AnimationTypes.Y, ypos, 1, AnimationTransitions.CubicEaseOut, 1);

         // add x and y to group callback
         eog.AddEaseObject(eox);
         eog.AddEaseObject(eoy);
     }
}

void EaseGroupComplete(EaseObjectGroup easeObjectGroup)
{
    // all animations have complete, re-randomize
    Randomize();
}