Пример #1
0
        public static Entity CollisionEntityFromObject(string entityName, TiledMapObject mapObject)
        {
            Entity entity = null;

            if (mapObject.ObjectType == TiledMapObjectType.Basic)
            {
                if (mapObject.Width > 0 && mapObject.Height > 0)
                {
                    entity = new Entity(entityName)
                             .AddComponent(new Transform2D()
                    {
                        LocalPosition = new Vector2(mapObject.X, mapObject.Y),
                        Rectangle     = new RectangleF(0, 0, mapObject.Width, mapObject.Height),
                        LocalRotation = MathHelper.ToRadians(mapObject.Rotation),
                        Origin        = Vector2.Zero
                    })
                             .AddComponent(new RectangleCollider2D())
                    ;
                }
            }
            else
            {
                // Only Basic object types are supported
            }

            return(entity);
        }
Пример #2
0
        public static Entity CollisionEntityFromObject(string entityName, TiledMapObject mapObject)
        {
            Entity entity = null;
            if (mapObject.ObjectType == TiledMapObjectType.Basic)
            {
                if (mapObject.Width > 0 && mapObject.Height > 0)
                {
                    entity = new Entity(entityName)
                    .AddComponent(new Transform2D()
                    {
                        LocalPosition = new Vector2(mapObject.X, mapObject.Y),
                        Rectangle = new RectangleF(0, 0, mapObject.Width, mapObject.Height),
                        LocalRotation = MathHelper.ToRadians(mapObject.Rotation),
                        Origin = Vector2.Zero
                    })
                    .AddComponent(new RectangleCollider2D())
                    ;
                }
            }
            else
            {
                // Only Basic object types are supported
            }

            return entity;
        }
Пример #3
0
        /// <summary>
        /// CollisionEntityFromObject
        /// </summary>
        /// <param name="entityName">entityName</param>
        /// <param name="mapObject">mapObject</param>
        /// <returns>Entity</returns>
        public static Entity CollisionEntityFromObject(string entityName, TiledMapObject mapObject)
        {
            Entity entity = null;

            if (mapObject.ObjectType == TiledMapObjectType.Basic)
            {
                if (mapObject.Width > 0 && mapObject.Height > 0)
                {
                    entity = CreateBasicEntity(entityName, mapObject)
                             .AddComponent(new RectangleCollider2D());
                }
            }
            else if (mapObject.ObjectType == TiledMapObjectType.Polyline)
            {
                if (mapObject.Points.Count > 1)
                {
                    entity = new Entity(entityName)
                             .AddComponent(new Transform2D()
                    {
                        LocalPosition = new Vector2(mapObject.X, mapObject.Y),
                        LocalRotation = MathHelper.ToRadians(mapObject.Rotation),
                    })
                             .AddComponent(new EdgeCollider2D()
                    {
                        Vertices = mapObject.Points.Select(p => new Vector2((float)p.X, (float)p.Y)).ToArray()
                    });
                }
            }
            else
            {
                // Only Basic and PolyLines object types are supported
            }

            return(entity);
        }
Пример #4
0
 private static Entity CreateBasicEntity(string entityName, TiledMapObject mapObject)
 {
     return(new Entity(entityName)
            .AddComponent(new Transform2D()
     {
         LocalPosition = new Vector2(mapObject.X, mapObject.Y),
         Rectangle = new RectangleF(0, 0, mapObject.Width, mapObject.Height),
         LocalRotation = MathHelper.ToRadians(mapObject.Rotation),
         Origin = Vector2.Zero
     }));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="TiledMapObjectLayer" /> class.
        /// </summary>
        /// <param name="tmxObjectLayer">The TMX parsed object layer</param>
        public TiledMapObjectLayer(TmxObjectGroup tmxObjectLayer)
        {
            this.ObjectLayerName = tmxObjectLayer.Name;
            this.Color = new Color(tmxObjectLayer.Color.R, tmxObjectLayer.Color.G, tmxObjectLayer.Color.B);
            this.Opacity = tmxObjectLayer.Opacity;
            this.Visible = tmxObjectLayer.Visible;

            this.Objects = new List<TiledMapObject>();
            this.Properties = new Dictionary<string, string>(tmxObjectLayer.Properties);

            foreach(var tmxObject in tmxObjectLayer.Objects)
            {
                var tiledMapObject = new TiledMapObject(tmxObject);
                this.Objects.Add(tiledMapObject);
            }
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TiledMapObjectLayer" /> class.
        /// </summary>
        /// <param name="tmxObjectLayer">The TMX parsed object layer</param>
        public TiledMapObjectLayer(TmxObjectGroup tmxObjectLayer)
        {
            this.ObjectLayerName = tmxObjectLayer.Name;
            this.Color           = new Color(tmxObjectLayer.Color.R, tmxObjectLayer.Color.G, tmxObjectLayer.Color.B);
            this.Opacity         = tmxObjectLayer.Opacity;
            this.Visible         = tmxObjectLayer.Visible;

            this.Objects    = new List <TiledMapObject>();
            this.Properties = new Dictionary <string, string>(tmxObjectLayer.Properties);

            foreach (var tmxObject in tmxObjectLayer.Objects)
            {
                var tiledMapObject = new TiledMapObject(tmxObject);
                this.Objects.Add(tiledMapObject);
            }
        }