Exemple #1
0
        public RectangleF?GetBounds(Vector2 pos, Vector2 scale, string name = "")
        {
            if (bounds.ContainsKey(name) == false)
            {
                return(null);
            }

            RectangleF rect = bounds[name];

            rect.X      *= scale.X;
            rect.Y      *= scale.Y;
            rect.Width  *= scale.X;
            rect.Height *= scale.Y;

            float x = pos.X + (-size.X / 2) * scale.X;
            float y = pos.Y + (-size.Y) * scale.Y;

            rect.Offset(x, y);
            if (rect.Width < 0)
            {
                rect.X     += rect.Width;
                rect.Width *= -1;
            }
            if (rect.Height < 0)
            {
                rect.Y      += rect.Height;
                rect.Height *= -1;
            }
            return(rect);
        }
Exemple #2
0
        public void Fill(clgf.Anim.Anim anim, clgf.Anim.Element elem, TextureMgr tmgr, string texpath)
        {
            //if (string.IsNullOrEmpty(elem.seednow))
            //{
            //    return;
            //}
            if (anim.parent.seeds.ContainsKey(elem.seednow) == false)
            {
                return;
            }

            var seed = anim.parent.seeds[elem.seednow];

            //string filename = System.IO.Path.GetFileNameWithoutExtension(elem.seed.texname);
            block      = tmgr.GetTexture(System.IO.Path.Combine(texpath, seed.texname));
            seedorient = seed.orient;
            seedsize   = seed.size;
            color      = elem.color;
            pos        = elem.pos;
            scale      = elem.scale;

            rotate = elem.rotate;
            bounds = Seed.CalcRotate(seed.size * scale, seed.orient * scale, rotate);
            bounds.Offset(pos.X, pos.Y);
            tag = elem.tag;
            if (tag == null)
            {
                tag = "";
            }
            if (tag.IndexOf("dummy:") == 0)
            {
                isdummy = true;
                tag     = tag.Substring(6);
            }
        }
Exemple #3
0
 public void InitWithTexture(Texture2D texture)
 {
     tex = texture;
     srcuv = new RectangleF(0, 0, 1.0f, 1.0f);
     seedsize.X = (float)tex.Width * srcuv.Width;
     seedsize.Y = (float)tex.Height * srcuv.Height;
     seedorient = new Vector2(0, 0);
 }
Exemple #4
0
 public void InitWithSeed(Seed seed, Texture.TextureMgr tmgr)
 {
     var block = tmgr.GetTexture(seed.texname);
     tex = block.parent.texture;
     srcuv = block.uv;
     seedsize = seed.size;
     seedorient = seed.orient;
 }
Exemple #5
0
 public void InitWithTexture(Texture2D texture)
 {
     tex        = texture;
     srcuv      = new RectangleF(0, 0, 1.0f, 1.0f);
     seedsize.X = (float)tex.Width * srcuv.Width;
     seedsize.Y = (float)tex.Height * srcuv.Height;
     seedorient = new Vector2(0, 0);
 }
Exemple #6
0
        public void InitWithSeed(Seed seed, Texture.TextureMgr tmgr)
        {
            var block = tmgr.GetTexture(seed.texname);

            tex        = block.parent.texture;
            srcuv      = block.uv;
            seedsize   = seed.size;
            seedorient = seed.orient;
        }
Exemple #7
0
 public TextureBlock(TexturePacket _p,RectangleF _uv)
 {
     parent = _p;
     parent.AddRef();
     uv = _uv;
 }
Exemple #8
0
        //public DrawFrame GetFrameByAdvTime(float delta)
        //{
        //    int lastid = (int)(timer * fps);
        //    if (play)
        //    {
        //        timer += delta;
        //    }
        //    int newid = (int)(timer * fps);
        //    while (newid - lastid > 1)
        //    {
        //        timer -= 1.0f / fps;//限制不跳帧
        //        newid --;
        //    }



        //    return frames[newid];
        //}
        public static SpriteAni CreateAni(Anim data, TextureMgr tmgr, string texpath = "")
        {
            SpriteAni ani = new SpriteAni();

            ani.fps = data.fps;
            while (ani.frames.Count < data.frames.Count)
            {
                ani.frames.Add(new DrawFrame(data.size));
            }
            int lastframe = 0;

            for (int i = 0; i < data.frames.Count; i++)
            {
                //while (ani.frames[i].drawElements.Count < data.frames[i].elems.Count)
                //{
                //    ani.frames[i].drawElements.Add(new DrawElement());
                //}
                #region fill frame
                for (int j = data.frames[i].elems.Count - 1; j >= 0; j--)
                {
                    if (string.IsNullOrEmpty(data.frames[i].elems[j].seednow))
                    {
                        continue;
                    }
                    DrawElement e = new DrawElement();
                    //在这里要反转层顺序


                    Element se = data.frames[i].elems[j];
                    if (string.IsNullOrEmpty(se.sound) == false)
                    {
                        ani.frames[i].sounds.Add(se.sound);
                        Console.WriteLine("find sound:" + se.sound);
                    }
                    e.Fill(data, se, tmgr, texpath);
                    if (e.isdummy == true || string.IsNullOrWhiteSpace(se.seedasdummy) == false)
                    {
                        Dummy dm = new Dummy();
                        dm.pos    = e.pos;
                        dm.rotate = e.rotate;
                        dm.name   = e.tag;
                        if (string.IsNullOrWhiteSpace(se.seedasdummy) == false)
                        {
                            dm.name = se.seedasdummy;
                        }
                        dm.seed = se.seed;
                        dm.elem = e;
                        ani.frames[i].dummys.Add(dm);
                    }
                    if (!e.isdummy)
                    {
                        ani.frames[i].drawElements.Add(e);

                        string tag = "";
                        if (string.IsNullOrEmpty(se.tag) == false)
                        {
                            tag = se.tag;
                        }
                        else
                        {
                            tag = "";
                        }
                        if (tag != "")
                        {
                            if (ani.frames[i].bounds.ContainsKey("") == false)
                            {
                                ani.frames[i].bounds[""] = e.bounds;
                            }
                            else
                            {
                                RectangleF src = ani.frames[i].bounds[""];
                                ani.frames[i].bounds[""] = RectangleF.Union(src, e.bounds);
                            }
                        }
                        if (ani.frames[i].bounds.ContainsKey(tag) == false)
                        {
                            ani.frames[i].bounds[tag] = e.bounds;
                        }
                        else
                        {
                            RectangleF src = ani.frames[i].bounds[tag];
                            ani.frames[i].bounds[tag] = RectangleF.Union(src, e.bounds);
                        }
                    }
                }
                #endregion
                if (i == 0 && data.frames[0].frametags.Count == 0)
                {
                    ani.elements["in"] = new AniElement(ani, 0, data.frames.Count - 1, false);
                }
                if (i == data.frames.Count - 1 && data.frames[i].frametags.Count == 0 && lastframe > 0)
                {
                    ani.elements["out"] = new AniElement(ani, lastframe + 1, data.frames.Count - 1, false);
                }
                if (data.frames[i].frametags.Count > 0)
                {
                    lastframe = i;
                    if (ani.elements.ContainsKey("in"))
                    {
                        if (ani.elements["in"].frameend == data.frames.Count - 1)
                        {
                            ani.elements["in"].frameend = i - 1;
                            ani.elements["in"].FixLife();
                        }
                    }
                }
                foreach (var tag in data.frames[i].frametags)
                {
                    if (ani.elements.ContainsKey(tag))
                    {
                        ani.elements[tag].frameend = i;
                        ani.elements[tag].FixLife();
                    }
                    else
                    {
                        ani.elements[tag] = new AniElement(ani, i, i, true);
                    }
                }
            }
            string[] ttags = new string[ani.framecount];
            foreach (var e in ani.elements)
            {
                for (int i = e.Value.framestart; i <= e.Value.frameend; i++)
                {
                    ttags[i] = e.Key;
                }
            }
            string begintag = "";
            int    begini   = 0;
            for (int i = 0; i < ani.framecount; i++)
            {
                if (string.IsNullOrEmpty(ttags[i]) == false)
                {
                    if (begintag != ttags[i])
                    {
                        if (begintag == "")
                        {
                        }
                        else
                        {
                            string endtag = ttags[i];
                            if (begini + 1 <= i - 1)
                            {
                                ani.elements[begintag + "-" + endtag] = new AniElement(ani, begini + 1, i - 1, false);
                            }
                        }
                    }
                    begintag = ttags[i];
                    begini   = i;
                }
            }
            ani.allelement = new AniElement(ani, 0, ani.framecount - 1, true);
            return(ani);
        }
Exemple #9
0
 public TextureBlock(TexturePacket _p, RectangleF _uv)
 {
     parent = _p;
     parent.AddRef();
     uv = _uv;
 }