Example #1
0
        public static AssetTileSheet Import(Cartridge cartridge, string assetName, Stream stream, int tileWidth, int tileHeight)
        {
            AssetTileSheet tileSheet = new AssetTileSheet(cartridge);

            tileSheet.Name = assetName;
            tileSheet.ImportImage(stream);

            tileSheet.TileWidth  = tileWidth;
            tileSheet.TileHeight = tileHeight;

            return(tileSheet);
        }
Example #2
0
        /// <summary>
        /// Chargement à partir d'un flux
        /// </summary>
        /// <param name="stream"></param>

        protected virtual async Task LoadAsync(Stream stream)
        {
            using (BinaryReader reader = new BinaryReader(stream, Encoding.UTF8, true))
            {
                this.LoadHeader(reader);

                while (stream.Position != stream.Length)
                {
                    var assetSize = reader.ReadInt32();
                    var assetType = (AssetTypes)reader.ReadInt32();

                    Asset asset = null;

                    switch (assetType)
                    {
                    default:
                        throw new Exception("Unknow assetType '" + assetType + "' !");

                    case AssetTypes.Sprite:
                        asset = new AssetSprite(this);
                        break;

                    case AssetTypes.TileSheet:
                        asset = new AssetTileSheet(this);
                        break;

                    case AssetTypes.FontSheet:
                        asset = new AssetFontSheet(this);
                        break;

                    case AssetTypes.MapTmx:
                        // MapTmx contient une liste d'AssetMap
                        asset = new AssetMapTmx(this);
                        break;

                    case AssetTypes.Sound:
                        asset = new AssetFile(this);
                        break;
                    }

                    asset.Size = assetSize;

                    await asset.ReadAsync(reader);

                    this.assets.Add(asset.Name, asset);
                }
            }

            this.IsLoaded = true;
        }