Exemple #1
0
 public Tile(Rectangle source, Dictionary <string, List <BoxCol> > boxColliders, Dictionary <string, string> properties, Texture2D texture, TilesetAnimation animation, int spacing, int margin)
 {
     Texture      = texture;
     Source       = source;
     BoxColliders = boxColliders;
     Properties   = properties;
     Animation    = animation;
     Spacing      = spacing;
     Margin       = margin;
 }
Exemple #2
0
        /// <summary>
        /// Reads the tielset from an .xnb file
        /// </summary>
        /// <param name="input">The ContentReader</param>
        /// <param name="existingInstance"></param>
        /// <returns>A Tileset</returns>
        protected override TRead Read(ContentReader input, TRead existingInstance)
        {
            // Read in the content properties in the exact same
            // order they were written in the corresponding writer
            // Read in the texture
            var texture = input.ReadObject <Texture2D>();

            // Read in the tile attributes
            var tileWidth  = input.ReadInt32();
            var tileHeight = input.ReadInt32();
            var margin     = input.ReadInt32();
            var spacing    = input.ReadInt32();
            var tileCount  = input.ReadInt32();

            // Read in the tiles - the number will vary based on the tileset
            var tiles = new Tile[tileCount];

            for (int i = 0; i < tileCount; i++)
            {
                // Get the source rectangle
                var source = new Rectangle(
                    input.ReadInt32(),
                    input.ReadInt32(),
                    tileWidth,
                    tileHeight);

                Dictionary <string, List <BoxCol> > boxCollisions = new Dictionary <string, List <BoxCol> >();
                int colliderCount = input.ReadInt32();
                for (int j = 0; j < colliderCount; j++)
                {
                    string        type         = input.ReadString();
                    int           count        = input.ReadInt32();
                    List <BoxCol> boxCollision = new List <BoxCol>();
                    for (int k = 0; k < count; k++)
                    {
                        BoxCol boxCol = new BoxCol();
                        boxCol.Rectangle = new Rectangle(
                            input.ReadInt32(),
                            input.ReadInt32(),
                            input.ReadInt32(),
                            input.ReadInt32());
                        boxCol.TriggerOnly = input.ReadBoolean();
                        boxCol.Name        = input.ReadString();
                        boxCollision.Add(boxCol);
                    }
                    boxCollisions.Add(type, boxCollision);
                }

                TilesetAnimation animation = new TilesetAnimation();
                animation.Frames = new List <TilesetFrame>();
                animation.Name   = input.ReadString();
                int frameCount = input.ReadInt32();

                for (int j = 0; j < frameCount; j++)
                {
                    animation.Frames.Add(new TilesetFrame(
                                             new Rectangle(input.ReadInt32(), input.ReadInt32(), input.ReadInt32(), input.ReadInt32()),
                                             (float)input.ReadDouble(), input.ReadInt32()));
                }

                int propLength = input.ReadInt32();
                Dictionary <string, string> properties = new Dictionary <string, string>();

                for (int j = 0; j < propLength; j++)
                {
                    properties.Add(input.ReadString(), input.ReadString());
                }

                // Create the tile
                tiles[i] = new Tile(source, boxCollisions, properties, texture, animation, spacing, margin);
            }

            // Construct and return the tileset
            return(new Tileset(tiles));
        }