Exemple #1
0
        public Spritemap(string id, string filename)
            : this(id)
        {
            ManagedSprites = new List <ManagedSprite>();

            BinaryReader reader = Resources.GetStream(filename);

            if (new string(reader.ReadChars(4)) != "HESm")
            {
                throw new ProtocolMismatchException("The file's magic number is not 'HESm' (HatlessEngine Spritemap)");
            }

            if (reader.ReadUInt16() != ProtocolVersion)
            {
                throw new ProtocolMismatchException("The file's protocol version is not equal to the required one (" + ProtocolVersion.ToString() + ")");
            }

            ushort spriteCount = reader.ReadUInt16();

            for (ushort i = 0; i < spriteCount; i++)
            {
                string targetSprite   = reader.ReadString();
                Point  position       = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point  size           = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point  origin         = new Point(reader.ReadSingle(), reader.ReadSingle());
                float  rotation       = reader.ReadSingle();
                string animationID    = reader.ReadString();
                int    startIndex     = reader.ReadInt32();
                float  animationSpeed = reader.ReadSingle();
                sbyte  depth          = reader.ReadSByte();

                ManagedSprite mSprite = new ManagedSprite(targetSprite, position, animationID, startIndex, animationSpeed, depth);
                mSprite.Size     = size;
                mSprite.Origin   = origin;
                mSprite.Rotation = rotation;

                ManagedSprites.Add(mSprite);
            }

            reader.Close();
        }
        public Spritemap(string id, string filename)
            : this(id)
        {
            ManagedSprites = new List<ManagedSprite>();

            BinaryReader reader = Resources.GetStream(filename);

            if (new string(reader.ReadChars(4)) != "HESm")
                throw new ProtocolMismatchException("The file's magic number is not 'HESm' (HatlessEngine Spritemap)");

            if (reader.ReadUInt16() != ProtocolVersion)
                throw new ProtocolMismatchException("The file's protocol version is not equal to the required one (" + ProtocolVersion + ")");

            ushort spriteCount = reader.ReadUInt16();

            for(ushort i = 0; i < spriteCount; i++)
            {
                string targetSprite = reader.ReadString();
                Point position = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point size = new Point(reader.ReadSingle(), reader.ReadSingle());
                Point origin = new Point(reader.ReadSingle(), reader.ReadSingle());
                float rotation = reader.ReadSingle();
                string animationId = reader.ReadString();
                int startIndex = reader.ReadInt32();
                float animationSpeed = reader.ReadSingle();
                sbyte depth = reader.ReadSByte();

                ManagedSprite mSprite = new ManagedSprite(targetSprite, position, animationId, startIndex, animationSpeed, depth)
                {
                    Size = size,
                    Origin = origin,
                    Rotation = rotation
                };

                ManagedSprites.Add(mSprite);
            }

            reader.Close();
        }