public void Initialize(Canvas parentCanvas, PhysicsControllerMain controller) { Controller = controller; _parentCanvas = parentCanvas; if (_parentCanvas == null) { throw new Exception(String.Format("The Camera Controller must exist in a Canvas with a PhysicsController.")); } // if there is a PhysicsController in the parent canvas, then we will wait // for it's Initialize event. foreach (UIElement element in _parentCanvas.Children) { if (element is PhysicsController) { Enabled = false; Controller = (element as PhysicsController).PhysicsMain; Controller.Initialized += new PhysicsControllerMain.InitializedHandler(CameraController_Initialized); break; } } ParallaxLayers = new List <ParallaxLayer>(); // _userControlLoaded = true; // create our "game loop" timer CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering); }
/// <summary> /// Adds ALL named XAML elements into the Physics simulation. /// </summary> /// <param name="cnvContainer">The container to add items from.</param> public void AddPhysicsBodyForCanvasWithBehaviors(Canvas cnvContainer) { #if SILVERLIGHT for (int i = 0; i < cnvContainer.Children.Count(); i++) #else for (int i = 0; i < cnvContainer.Children.Count; i++) #endif { FrameworkElement element = cnvContainer.Children[i] as FrameworkElement; string elemName = element.GetValue(Canvas.NameProperty).ToString(); element.SetValue(Canvas.TagProperty, elemName); } PhysicsControllerMain.EnsureUniqueNames(cnvContainer, false); List <PhysicsObjectMain> objectsToAdd = new List <PhysicsObjectMain>(); #if SILVERLIGHT for (int i = 0; i < cnvContainer.Children.Count() - 1; i++) #else for (int i = 0; i < cnvContainer.Children.Count - 1; i++) #endif { FrameworkElement element = cnvContainer.Children[i] as FrameworkElement; PhysicsObjectMain physObject = element.GetValue(PhysicsObjectMain.PhysicsObjectProperty) as PhysicsObjectMain; if (physObject != null) { objectsToAdd.Add(physObject); } } foreach (PhysicsObjectMain physObject in objectsToAdd) { AddPhysicsBody(physObject); } #if SILVERLIGHT for (int i = cnvContainer.Children.Count() - 1; i >= 0; i--) #else for (int i = cnvContainer.Children.Count - 1; i >= 0; i--) #endif { FrameworkElement element = cnvContainer.Children[i] as FrameworkElement; PhysicsJointMain joint = element.GetValue(PhysicsJointMain.PhysicsJointProperty) as PhysicsJointMain; if (joint != null) { AddJoint(joint); } } }
public static PhysicsControllerMain FindController(FrameworkElement element) { while (element != null) { PhysicsControllerMain context = PhysicsControllerMain.GetPhysicsController(element); if (context != null) { return(context); } element = VisualTreeHelper.GetParent(element) as FrameworkElement; } return(null); }
/// <summary> /// A utility function to get a point that is a given distance and angle from another point. /// </summary> /// <param name="angle">The angle to travel</param> /// <param name="distance">The distance (in pixels) to go</param> /// <param name="ptStart">The start point</param> /// <returns></returns> public static Point GetPointFromDistanceAngle(double angle, double distance, Point ptStart) { return(PhysicsControllerMain.GetPointFromDistanceAngle(angle, distance, ptStart)); }
/// <summary> /// Get the distance, in pixels between two points. /// </summary> public static double DistanceBetweenTwoPoints(Point pt1, Point pt2) { return(PhysicsControllerMain.DistanceBetweenTwoPoints(pt1, pt2)); }
/// <summary> /// Create a path object based on a list of vertices - used when creating geometry /// </summary> public static System.Windows.Shapes.Path CreatePathFromVertices(Vertices vertices, double width, double height) { return(PhysicsControllerMain.CreatePathFromVertices(vertices, width, height)); }
/// <summary> /// Given a list of points, get the overall width and height to cover them all, as well as the mininum X and Y values occurring. /// </summary> /// <param name="points">The list of points</param> public static void GetPointDimensions(List <Point> points, out double width, out double height, out double minX, out double minY) { PhysicsControllerMain.GetPointDimensions(points, out width, out height, out minX, out minY); }
public static void SetPhysicsController(DependencyObject target, PhysicsControllerMain value) { target.SetValue(PhysicsControllerMain.PhysicsControllerProperty, value); }