Esempio n. 1
0
 public AniElement(SpriteAni ani, int fstart, int fend, bool bloop)
 {
     this.ani   = ani;
     framestart = fstart;
     frameend   = fend;
     loop       = bloop;
     life       = frameend - framestart + 1;
 }
Esempio n. 2
0
        public static SpriteAni CreateAni(Sprite sprite, string ani, Texture.TextureMgr tmgr, string texpath = "")
        {
            string hash = sprite.name + "|" + ani;

            if (bufs.ContainsKey(hash) == false)
            {
                bufs[hash] = SpriteAni.CreateAni(sprite.anims[ani], tmgr, texpath);
            }


            return(bufs[hash]);
        }
Esempio n. 3
0
 public void Play(AniElement elem, playtag tag, Action whenplay = null)
 {
     if (tag == playtag.play_immediate)
     {
         element_queue.Clear();
         curfstart  = elem.framestart;
         curfend    = elem.frameend;
         curelife   = elem.life;
         cureloop   = elem.loop;
         curframeid = 0;
         _data      = elem.ani;
         timer      = 0;
         instate    = false;
         if (whenplay != null)
         {
             whenplay();
         }
     }
     if (tag == playtag.play_afterthiselement)
     {
         element_queue.Clear();
         element_queue.Enqueue(elem);
         if (whenplay != null)
         {
             if (monitor == null)
             {
                 monitor = new Dictionary <AniElement, Action>();
             }
             monitor[elem] = whenplay;
         }
     }
     if (tag == playtag.play_wait)
     {
         element_queue.Enqueue(elem);
         if (whenplay != null)
         {
             if (monitor == null)
             {
                 monitor = new Dictionary <AniElement, Action>();
             }
             monitor[elem] = whenplay;
         }
     }
 }
Esempio n. 4
0
 public void State(AniElement elem, bool bimmediate = true, Action whenplay = null)
 {
     element_state = elem;
     if (whenplay != null)
     {
         if (monitor == null)
         {
             monitor = new Dictionary <AniElement, Action>();
         }
         monitor[elem] = whenplay;
     }
     if (bimmediate && elem != null && element_queue.Count == 0)
     {
         curfstart  = element_state.framestart;
         curfend    = element_state.frameend;
         cureloop   = element_state.loop;
         _data      = element_state.ani;
         curframeid = 0;
         timer      = 0;
         instate    = true;
     }
 }
Esempio n. 5
0
        public void AdvTime(float delta)
        {
            int lastid = (int)(timer * _data.fps);

            if (bplay)
            {
                timer += delta;
            }
            curframeid = (int)(timer * _data.fps);
            if (curframeid == lastid && curframeid <= (curfend - curfstart))
            {
                return;
            }
            if (skipframe)
            {
                while (curframeid - lastid > 1)
                {
                    timer -= 1.0f / _data.fps;//限制不跳帧
                    curframeid--;
                }
            }
            curelife -= (curframeid - lastid);
            if (curelife <= 0)
            {
                curelife = 0;
                if (element_queue.Count > 0)
                {
                    var e = element_queue.Dequeue();
                    if (monitor != null)
                    {
                        if (monitor.ContainsKey(e))
                        {
                            monitor[e]();
                            monitor.Remove(e);
                        }
                    }
                    curfstart  = e.framestart;
                    curfend    = e.frameend;
                    cureloop   = e.loop;
                    curelife   = e.life;
                    curframeid = 0;
                    timer      = 0;
                    _data      = e.ani;
                    instate    = false;
                }
                else
                {
                    if (element_state == null)
                    {
                        cureloop = false;
                    }
                    else
                    {
                        if (monitor != null)
                        {
                            if (monitor.ContainsKey(element_state))
                            {
                                monitor[element_state]();
                                monitor.Remove(element_state);
                            }
                        }
                        curfstart = element_state.framestart;
                        curfend   = element_state.frameend;
                        cureloop  = element_state.loop;
                        _data     = element_state.ani;
                    }
                    instate = true;
                }
            }
            if (cureloop)
            {
                while (curframeid >= (curfend - curfstart + 1))
                {
                    curframeid = curframeid - (curfend - curfstart + 1);
                    timer     -= (curfend - curfstart + 1) / _data.fps;
                }
            }
            else
            {
                if (curframeid >= (curfend - curfstart + 1))
                {
                    curframeid = (curfend - curfstart + 1) - 1;
                }
            }
        }
Esempio n. 6
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);
        }