protected override void OnAttached()
        {
            base.OnAttached();

            _physicsJointMain.VisualElement = this.AssociatedObject;

            this.AssociatedObject.Loaded += new RoutedEventHandler(AssociatedObject_Loaded);

            PhysicsJointMain.SetPhysicsJoint(this.AssociatedObject, _physicsJointMain);
        }
Esempio n. 2
0
        private void btnAddDoll_Click(object sender, RoutedEventArgs e)
        {
            ucRagDoll _ucRagDollNew = new ucRagDoll();

            cnvGame.Children.Add(_ucRagDollNew);

            // we want to change the collision group for this new doll,
            // so that it will collide with other ragdolls of this type.
            _collisionGroup++;

            foreach (FrameworkElement element in _ucRagDollNew.LayoutRoot.Children)
            {
                PhysicsJointMain joint = element.GetValue(PhysicsJointMain.PhysicsJointProperty) as PhysicsJointMain;
                if (joint != null)
                {
                    joint.CollisionGroup = _collisionGroup;
                }
            }

            _ucRagDollNew.SetValue(Canvas.LeftProperty, Convert.ToDouble(_rand.Next(50, 950)));
            _ucRagDollNew.SetValue(Canvas.TopProperty, 0D);

            _physicsController.AddPhysicsBodyForCanvasWithBehaviors(_ucRagDollNew.LayoutRoot);
        }