Exemplo n.º 1
0
        /// <summary>
        /// Duplicates the given Body along the given path for approximatly the given copies.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="path">The path.</param>
        /// <param name="shapes">The shapes.</param>
        /// <param name="type">The type.</param>
        /// <param name="copies">The copies.</param>
        /// <param name="userData"></param>
        /// <returns></returns>
        public static List <Body> EvenlyDistributeShapesAlongPath(World world, Path path, IEnumerable <Shape> shapes, BodyType type, int copies, object userData = null, IPhysicsDependencyBody physicsBody = null)
        {
            List <Vector3> centers  = path.SubdivideEvenly(copies);
            List <Body>    bodyList = new List <Body>();

            for (int i = 0; i < centers.Count; i++)
            {
                Body b = world.CreateBody(physicsBody: physicsBody);

                // copy the type from original body
                b.BodyType = type;
                b.Position = new Vector2(centers[i].X, centers[i].Y);
                b.Rotation = centers[i].Z;
                b.Tag      = userData;

                foreach (Shape shape in shapes)
                {
                    b.CreateFixture(shape);
                }

                bodyList.Add(b);
            }

            return(bodyList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Duplicates the given Body along the given path for approximatly the given copies.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="path">The path.</param>
        /// <param name="shape">The shape.</param>
        /// <param name="type">The type.</param>
        /// <param name="copies">The copies.</param>
        /// <param name="userData">The user data.</param>
        /// <returns></returns>
        public static List <Body> EvenlyDistributeShapesAlongPath(World world, Path path, Shape shape, BodyType type, int copies, object userData = null, IPhysicsDependencyBody physicsBody = null)
        {
            List <Shape> shapes = new List <Shape>(1);

            shapes.Add(shape);

            return(EvenlyDistributeShapesAlongPath(world, path, shapes, type, copies, userData, physicsBody));
        }