Line 25: |
Line 25: |
| ==Read assets== | | ==Read assets== |
| ===Read mod assets=== | | ===Read mod assets=== |
− | You can read custom assets from your mod folder. The normal convention is to have them in an <tt>assets</tt> subfolder, though that's not required. To read a file, you specify the type and path relative to your mod folder. For example: | + | You can read custom assets from your mod folder by specifying its path (relative to your mod folder) and type. For example: |
| <source lang="c#"> | | <source lang="c#"> |
− | // read a PNG file | + | // read an image file |
| Texture2D texture = helper.Content.Load<Texture2D>("assets/texture.png", ContentSource.ModFolder); | | Texture2D texture = helper.Content.Load<Texture2D>("assets/texture.png", ContentSource.ModFolder); |
| | | |
| // read a map file | | // read a map file |
− | Map map = helper.Content.Load<Texture2D>("assets/map.tbin", ContentSource.ModFolder); | + | Map map = helper.Content.Load<Map>("assets/map.tbin", ContentSource.ModFolder); |
| | | |
− | // read an XNB file | + | // read a data file |
− | IDictionary<string, string> data = helper.Content.Load<Dictionary<string, string>>("assets/data.xnb", ContentSource.ModFolder); | + | IDictionary<string, string> data = helper.Content.Load<Dictionary<string, string>>("assets/data.json", ContentSource.ModFolder); |
| </source> | | </source> |
| | | |
Line 63: |
Line 63: |
| | | |
| Some usage notes: | | Some usage notes: |
| + | * The normal convention is to have them in an <tt>assets</tt> subfolder, though that's not required. |
| * Don't worry about which path separators you use; SMAPI will normalise them automatically. | | * Don't worry about which path separators you use; SMAPI will normalise them automatically. |
| * To avoid performance issues, don't call <tt>content.Load<T></tt> repeatedly in draw code. Instead, load your asset once and reuse it. | | * To avoid performance issues, don't call <tt>content.Load<T></tt> repeatedly in draw code. Instead, load your asset once and reuse it. |