Beispiel #1
0
        public static TmxObjectGroup LoadTmxObjectGroup(this TmxObjectGroup group, TmxMap map, XElement xObjectGroup)
        {
            group.Map             = map;
            group.Name            = (string)xObjectGroup.Attribute("name") ?? string.Empty;
            group.Color           = TiledMapLoader.ParseColor(xObjectGroup.Attribute("color"));
            group.Opacity         = (float?)xObjectGroup.Attribute("opacity") ?? 1.0f;
            group.Visible         = (bool?)xObjectGroup.Attribute("visible") ?? true;
            group.OffsetX         = (float?)xObjectGroup.Attribute("offsetx") ?? 0.0f;
            group.OffsetY         = (float?)xObjectGroup.Attribute("offsety") ?? 0.0f;
            group.ParallaxFactorX = (float?)xObjectGroup.Attribute("parallaxx") ?? 1.0f;
            group.ParallaxFactorY = (float?)xObjectGroup.Attribute("parallaxy") ?? 1.0f;

            var drawOrderDict = new Dictionary <string, DrawOrderType> {
                { "unknown", DrawOrderType.UnknownOrder },
                { "topdown", DrawOrderType.IndexOrder },
                { "index", DrawOrderType.TopDown }
            };

            var drawOrderValue = (string)xObjectGroup.Attribute("draworder");

            if (drawOrderValue != null)
            {
                group.DrawOrder = drawOrderDict[drawOrderValue];
            }

            group.Objects = new TmxList <TmxObject>();
            foreach (var e in xObjectGroup.Elements("object"))
            {
                group.Objects.Add(new TmxObject().LoadTmxObject(map, e));
            }

            group.Properties = ParsePropertyDict(xObjectGroup.Element("properties"));

            return(group);
        }
Beispiel #2
0
        public static TmxImage LoadTmxImage(this TmxImage image, XElement xImage, string tmxDir = "")
        {
            var xSource = xImage.Attribute("source");

            if (xSource != null)
            {
                // Append directory if present
                image.Source = Path.Combine(tmxDir, (string)xSource);

                /*using (var stream = TitleContainer.OpenStream(image.Source))
                 *      image.Texture = Texture2D.FromStream(Core.GraphicsDevice, stream);*/

                image.Source  = image.Source.Substring(Core.Content.RootDirectory.Length + 1);
                image.Source  = image.Source.Remove(image.Source.LastIndexOf('.'));
                image.Texture = (Core.Scene?.Content ?? Core.Content).LoadTexture(image.Source);
            }
            else
            {
                image.Format = (string)xImage.Attribute("format");
                var xData         = xImage.Element("data");
                var decodedStream = new TmxBase64Data(xData);
                image.Data = decodedStream.Data;
                throw new NotSupportedException("Stream Data loading is not yet supported");
            }

            image.Trans  = TiledMapLoader.ParseColor(xImage.Attribute("trans"));
            image.Width  = (int?)xImage.Attribute("width") ?? 0;
            image.Height = (int?)xImage.Attribute("height") ?? 0;

            return(image);
        }
Beispiel #3
0
        public static TmxImage LoadTmxImage(this TmxImage image, XElement xImage, bool headless = false, string tmxDir = "")
        {
            var xSource = xImage.Attribute("source");

            if (xSource != null)
            {
                if (!headless)
                {
                    // Append directory if present
                    image.Source = Path.Combine(tmxDir, (string)xSource);
                    using (var stream = TitleContainer.OpenStream(image.Source))
                        image.Texture = Texture2D.FromStream(Core.GraphicsDevice, stream);
                }
            }
            else
            {
                image.Format = (string)xImage.Attribute("format");
                var xData         = xImage.Element("data");
                var decodedStream = new TmxBase64Data(xData);
                image.Data = decodedStream.Data;
                throw new NotSupportedException("Stream Data loading is not yet supported");
            }

            image.Trans  = TiledMapLoader.ParseColor(xImage.Attribute("trans"));
            image.Width  = (int?)xImage.Attribute("width") ?? 0;
            image.Height = (int?)xImage.Attribute("height") ?? 0;

            return(image);
        }