コード例 #1
0
        void Animator()
        {
            if (Animation != null)
            {
                if (Animation.Textures != null)
                {
                    if (FrameCurrent > Animation.Textures.Count)
                    {
                        FrameCurrent = 0;
                    }

                    sprite = Animation.Textures[FrameCurrent];

                    if (time > sprite.Wait)
                    {
                        time         = 0;
                        FrameCurrent = Math.Min(FrameCurrent + 1, Animation.Textures.Count);
                    }

                    if (FrameCurrent == Animation.Textures.Count)
                    {
                        if (Animation.Loop)
                        {
                            FrameCurrent = 0;
                        }
                        else
                        {
                            FrameCurrent = Animation.Textures.Count - 1;

                            if (BackAnimation != null)
                            {
                                time      = 0;
                                Animation = BackAnimation;
                            }
                        }
                    }

                    time += fps;
                }
            }
        }
コード例 #2
0
        /* =================================================================================================================================================================== */
        /* LEER ARCHIVO */
        /* =================================================================================================================================================================== */

        bool Desserialize(byte[] data)
        {
            try
            {
                Animations.Clear();

                using (MemoryStream m = new MemoryStream(data))
                {
                    using (BinaryReader reader = new BinaryReader(m))
                    {
                        string _header = "ABOCHAR";
                        string Header  = Encoding.ASCII.GetString(reader.ReadBytes(_header.Length)); //Obtenemos el Header

                        int Ani_Total = reader.ReadInt32();

                        if (Header == _header)
                        {
                            for (int a = 0; a < (Ani_Total); a++)
                            {
                                CharProperties animation = new CharProperties();

                                int name_length = reader.ReadInt32();
                                animation.Name = Encoding.ASCII.GetString(reader.ReadBytes(name_length)); // Obtenemos el nombre de la animacion

                                bool loop = Convert.ToBoolean(reader.ReadInt32());
                                animation.Loop = loop;

                                int Text_Total = reader.ReadInt32();

                                animation.Textures = new List <SpriteProperties>();

                                for (int t = 0; t < (Text_Total); t++)
                                {
                                    SpriteProperties Sprite = new SpriteProperties();

                                    int  wait  = reader.ReadInt32();
                                    bool turnX = Convert.ToBoolean(reader.ReadInt32());
                                    bool turnY = Convert.ToBoolean(reader.ReadInt32());

                                    Sprite.Wait  = wait;
                                    Sprite.TurnX = turnX;
                                    Sprite.TurnY = turnY;

                                    int x = reader.ReadInt32();
                                    int y = reader.ReadInt32();

                                    Sprite.Position = new Vector2(x, y);

                                    int Sprite_Size = reader.ReadInt32();

                                    Sprite.Texture = toTexture(reader.ReadBytes(Sprite_Size));

                                    animation.Textures.Add(Sprite);
                                }

                                Animations.Add(animation);
                            }

                            return(true);
                        }
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
                Animations.Clear();
                return(false);
            }
        }