Example #1
0
        public bool loop; //是否循环

        #endregion Fields

        #region Constructors

        public AniElement(SpriteAni ani, int fstart, int fend, bool bloop)
        {
            this.ani = ani;
            framestart = fstart;
            frameend = fend;
            loop = bloop;
            life = frameend - framestart + 1;
        }
Example #2
0
 public AniElement(SpriteAni ani, int fstart, int fend, bool bloop)
 {
     this.ani   = ani;
     framestart = fstart;
     frameend   = fend;
     loop       = bloop;
     life       = frameend - framestart + 1;
 }
Example #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;
         }
     }
 }
Example #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;
     }
 }
Example #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;
                }
            }
        }
Example #6
0
        public static SpriteAni CreateAni(Anim data, string aniname)
        {
            SpriteAni ani = new SpriteAni();

            ani.fps = data.fps;
            while (ani.frames.Count < data.frames.Count)
            {
                ani.frames.Add(new DrawFrame(data.size, ani.frames.Count, aniname));
            }
            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(System.IO.Path.GetFileNameWithoutExtension(se.sound));
                    }


                    //e.Fill(data, se);
                    bool e_isdummy = (se.tag.IndexOf("dummy:") == 0);
                    if (e_isdummy == true || string.IsNullOrEmpty(se.seedasdummy) == false)
                    {
                        Dummy dm = new Dummy();
                        dm.pos    = se.pos;
                        dm.rotate = se.rotate;

                        if (string.IsNullOrEmpty(se.seedasdummy) == false)
                        {
                            dm.name = se.seedasdummy;
                        }
                        else
                        {
                            dm.name = se.tag.Substring(6);
                        }
                        ani.frames[i].dummys.Add(dm);
                    }
                    if (!e_isdummy)
                    {
                        Rect e_bounds = Calc_Bound(data, se);
                        //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
                            {
                                Rect src = ani.frames[i].bounds[""];
                                ani.frames[i].bounds[""] = Rect_Union(src, e_bounds);
                            }
                        }
                        if (ani.frames[i].bounds.ContainsKey(tag) == false)
                        {
                            ani.frames[i].bounds[tag] = e_bounds;
                        }
                        else
                        {
                            Rect src = ani.frames[i].bounds[tag];
                            ani.frames[i].bounds[tag] = Rect_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);
        }
Example #7
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;
     }
 }
Example #8
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;
         }
     }
 }
Example #9
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;
                }
            }
        }
Example #10
0
 public SpriteAniController(AniElement state)
 {
     //this.data = data;
     this.element_state = state;
     this._data = state.ani;
     if (element_state != null)
     {
         curfstart = element_state.framestart;
         curfend = element_state.frameend;
         cureloop = element_state.loop;
         _data = element_state.ani;
         curframeid = 0;
         timer = 0;
     }
     this.bplay = true;
     instate = true;
     this.skipframe = true;
 }
Example #11
0
        public static SpriteAni CreateAni(Anim data,string aniname)
        {
            SpriteAni ani = new SpriteAni();
            ani.fps = data.fps;
            while (ani.frames.Count < data.frames.Count)
            {
                ani.frames.Add(new DrawFrame(data.size, ani.frames.Count,aniname));
            }
            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(System.IO.Path.GetFileNameWithoutExtension(se.sound));
                    }

                    //e.Fill(data, se);
                    bool e_isdummy = (se.tag.IndexOf("dummy:") == 0);
                    if (e_isdummy == true || string.IsNullOrEmpty(se.seedasdummy) == false)
                    {
                        Dummy dm = new Dummy();
                        dm.pos = se.pos;
                        dm.rotate = se.rotate;

                        if (string.IsNullOrEmpty(se.seedasdummy) == false)
                            dm.name = se.seedasdummy;
                        else
                            dm.name = se.tag.Substring(6);
                        ani.frames[i].dummys.Add(dm);
                    }
                    if(!e_isdummy)
                    {
                        Rect e_bounds = Calc_Bound(data, se);
                        //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
                            {
                                Rect src = ani.frames[i].bounds[""];
                                ani.frames[i].bounds[""] = Rect_Union(src, e_bounds);
                            }
                        }
                        if (ani.frames[i].bounds.ContainsKey(tag) == false)
                        {
                            ani.frames[i].bounds[tag] = e_bounds;
                        }
                        else
                        {
                            Rect src = ani.frames[i].bounds[tag];
                            ani.frames[i].bounds[tag] = Rect_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;
        }