示例#1
0
        public static Frame CreateFromNode(Wz_Node frameNode, GraphicsDevice graphicsDevice, GlobalFindNodeFunction findNode)
        {
            if (frameNode == null || frameNode.Value == null)
            {
                return(null);
            }

            while (frameNode.Value is Wz_Uol)
            {
                Wz_Uol  uol     = frameNode.Value as Wz_Uol;
                Wz_Node uolNode = uol.HandleUol(frameNode);
                if (uolNode != null)
                {
                    frameNode = uolNode;
                }
            }
            if (frameNode.Value is Wz_Png)
            {
                var    linkNode = frameNode.GetLinkedSourceNode(findNode);
                Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)frameNode.Value;

                var frame = new Frame(png.ToTexture(graphicsDevice))
                {
                    Png = png,
                };

                foreach (Wz_Node propNode in frameNode.Nodes)
                {
                    switch (propNode.Text)
                    {
                    case "origin":
                        frame.Origin = (propNode.Value as Wz_Vector).ToPoint();
                        break;

                    case "delay":
                        frame.Delay = propNode.GetValue <int>();
                        break;

                    case "z":
                        frame.Z = propNode.GetValue <int>();
                        break;

                    case "a0":
                        frame.A0 = propNode.GetValue <int>();
                        break;

                    case "a1":
                        frame.A1 = propNode.GetValue <int>();
                        break;
                    }
                }

                if (frame.Delay == 0)
                {
                    frame.Delay = 100;//给予默认delay
                }
                return(frame);
            }
            return(null);
        }
示例#2
0
        public static Texture2D ToTexture(this Wz_Png png, GraphicsDevice graphicsDevice)
        {
            var format = GetTextureFormatOfPng(png.Form);

            if (format == SurfaceFormat.Bgra4444)
            {
                //检测是否支持 pre-win8
                if (!graphicsDevice.IsSupportBgra4444())
                {
                    format = SurfaceFormat.Bgra32;
                }
            }
            else if (format == SurfaceFormat.Bgr565)
            {
                //检测是否支持 pre-win8
                if (!graphicsDevice.IsSupportBgr565())
                {
                    format = SurfaceFormat.Bgra32;
                }
            }
            else if (format == SurfaceFormat.Bgra5551)
            {
                //检测是否支持 pre-win8
                if (!graphicsDevice.IsSupportBgra5551())
                {
                    format = SurfaceFormat.Bgra32;
                }
            }

            var t2d = new Texture2D(graphicsDevice, png.Width, png.Height, false, format);

            png.ToTexture(t2d, Point.Zero);
            return(t2d);
        }
        public void Load(AtlasPage page, string path)
        {
            var frameNode = this.TopNode.FindNodeByPath(path);

            if (frameNode == null || frameNode.Value == null)
            {
                return;
            }

            if (frameNode.Value is Wz_Uol)
            {
                Wz_Uol  uol     = frameNode.Value as Wz_Uol;
                Wz_Node uolNode = uol.HandleUol(frameNode);
                if (uolNode != null)
                {
                    frameNode = uolNode;
                }
            }

            if (frameNode.Value is Wz_Png)
            {
                var    linkNode = frameNode.GetLinkedSourceNode(FindNodeFunction);
                Wz_Png png      = linkNode?.GetValue <Wz_Png>() ?? (Wz_Png)frameNode.Value;
                page.rendererObject = png.ToTexture(this.GraphicsDevice);
                page.width          = png.Width;
                page.height         = png.Height;
            }
        }
示例#4
0
        public static Texture2D ToTexture(this Wz_Png png, GraphicsDevice graphicsDevice)
        {
            var       format = GetTextureFormatOfPng(png.Form);
            Texture2D t2d    = null;

            if (format == SurfaceFormat.Bgra4444)
            {
                //检测是否支持
                if (graphicsDevice.IsSupportBgra4444())
                {
                    t2d = MonogameUtils.CreateTexture_BGRA4444(graphicsDevice, png.Width, png.Height);
                }
                else
                {
                    format = SurfaceFormat.Bgra32;
                }
            }
            if (t2d == null)
            {
                t2d = new Texture2D(graphicsDevice, png.Width, png.Height, false, format);
            }

            png.ToTexture(t2d, Point.Zero);
            return(t2d);
        }
示例#5
0
        public void ShowImage(Wz_Png png)
        {
            //添加到动画控件
            var frame = new Animation.Frame()
            {
                Texture = png.ToTexture(this.GraphicsDevice),
                Png     = png,
                Delay   = 0,
                Origin  = Point.Zero,
            };

            var frameData = new Animation.FrameAnimationData();

            frameData.Frames.Add(frame);

            this.ShowAnimation(frameData);
        }