コード例 #1
0
        public static TmxImageLayer LoadTmxImageLayer(this TmxImageLayer layer, TmxMap map, XElement xImageLayer, string tmxDir = "")
        {
            layer.Map  = map;
            layer.Name = (string)xImageLayer.Attribute("name");

            layer.Width           = (int?)xImageLayer.Attribute("width");
            layer.Height          = (int?)xImageLayer.Attribute("height");
            layer.Visible         = (bool?)xImageLayer.Attribute("visible") ?? true;
            layer.Opacity         = (float?)xImageLayer.Attribute("opacity") ?? 1.0f;
            layer.OffsetX         = (float?)xImageLayer.Attribute("offsetx") ?? 0.0f;
            layer.OffsetY         = (float?)xImageLayer.Attribute("offsety") ?? 0.0f;
            layer.ParallaxFactorX = (float?)xImageLayer.Attribute("parallaxx") ?? 1.0f;
            layer.ParallaxFactorY = (float?)xImageLayer.Attribute("parallaxy") ?? 1.0f;

            var xImage = xImageLayer.Element("image");

            if (xImage != null)
            {
                layer.Image = new TmxImage().LoadTmxImage(xImage, tmxDir);
            }

            layer.Properties = ParsePropertyDict(xImageLayer.Element("properties"));

            return(layer);
        }
コード例 #2
0
        public TmxGroup(TmxMap map, XElement xGroup, int width, int height, string tmxDirectory)
        {
            this.map = map;
            Name     = (string)xGroup.Attribute("name") ?? string.Empty;
            Opacity  = (float?)xGroup.Attribute("opacity") ?? 1.0f;
            Visible  = (bool?)xGroup.Attribute("visible") ?? true;
            OffsetX  = (float?)xGroup.Attribute("offsetx") ?? 0.0f;
            OffsetY  = (float?)xGroup.Attribute("offsety") ?? 0.0f;

            Properties = PropertyDict.ParsePropertyDict(xGroup.Element("properties"));

            layers       = new TmxList <ITmxLayer>();
            tileLayers   = new TmxList <TmxLayer>();
            objectGroups = new TmxList <TmxObjectGroup>();
            imageLayers  = new TmxList <TmxImageLayer>();
            groups       = new TmxList <TmxGroup>();
            foreach (var e in xGroup.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group"))
            {
                ITmxLayer layer;
                switch (e.Name.LocalName)
                {
                case "layer":
                    var tileLayer = new TmxLayer(map, e, width, height);
                    layer = tileLayer;
                    tileLayers.Add(tileLayer);
                    break;

                case "objectgroup":
                    var objectgroup = new TmxObjectGroup(map, e);
                    layer = objectgroup;
                    objectGroups.Add(objectgroup);
                    break;

                case "imagelayer":
                    var imagelayer = new TmxImageLayer(map, e, tmxDirectory);
                    layer = imagelayer;
                    imageLayers.Add(imagelayer);
                    break;

                case "group":
                    var group = new TmxGroup(map, e, width, height, tmxDirectory);
                    layer = group;
                    groups.Add(group);
                    break;

                default:
                    throw new InvalidOperationException();
                }
                layers.Add(layer);
            }
        }
コード例 #3
0
        /// <summary>
        /// parses all the layers in xEle putting them in the container
        /// </summary>
        public static void ParseLayers(object container, XElement xEle, TmxMap map, int width, int height, string tmxDirectory)
        {
            foreach (var e in xEle.Elements().Where(x => x.Name == "layer" || x.Name == "objectgroup" || x.Name == "imagelayer" || x.Name == "group"))
            {
                ITmxLayer layer;
                switch (e.Name.LocalName)
                {
                case "layer":
                    var tileLayer = new TmxLayer().LoadTmxLayer(map, e, width, height);
                    layer = tileLayer;

                    if (container is TmxMap m)
                    {
                        m.TileLayers.Add(tileLayer);
                    }
                    else if (container is TmxGroup g)
                    {
                        g.TileLayers.Add(tileLayer);
                    }
                    break;

                case "objectgroup":
                    var objectgroup = new TmxObjectGroup().LoadTmxObjectGroup(map, e);
                    layer = objectgroup;

                    if (container is TmxMap mm)
                    {
                        mm.ObjectGroups.Add(objectgroup);
                    }
                    else if (container is TmxGroup gg)
                    {
                        gg.ObjectGroups.Add(objectgroup);
                    }
                    break;

                case "imagelayer":
                    var imagelayer = new TmxImageLayer().LoadTmxImageLayer(map, e, tmxDirectory);
                    layer = imagelayer;

                    if (container is TmxMap mmm)
                    {
                        mmm.ImageLayers.Add(imagelayer);
                    }
                    else if (container is TmxGroup ggg)
                    {
                        ggg.ImageLayers.Add(imagelayer);
                    }
                    break;

                case "group":
                    var newGroup = new TmxGroup().LoadTmxGroup(map, e, width, height, tmxDirectory);
                    layer = newGroup;

                    if (container is TmxMap mmmm)
                    {
                        mmmm.Groups.Add(newGroup);
                    }
                    else if (container is TmxGroup gggg)
                    {
                        gggg.Groups.Add(newGroup);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }

                if (container is TmxMap mmmmm)
                {
                    mmmmm.Layers.Add(layer);
                }
                else if (container is TmxGroup g)
                {
                    g.Layers.Add(layer);
                }
            }
        }