diff --git a/Docs/MonoGame.Extended/Content.md b/Docs/MonoGame.Extended/Content.md new file mode 100644 index 00000000..2aea4878 --- /dev/null +++ b/Docs/MonoGame.Extended/Content.md @@ -0,0 +1,64 @@ +# ContentManager extensions + +## ContentManager.OpenStream + +`System.IO.Stream ContentManager.OpenStream(string filename)` + +**OpenStream** allows easy access to `TitleContainer.OpenStream` so you can use the `Game.Content` object to load compiled resources *and* included resources. + +```csharp +// my-file.txt is in the RootDirectory +var stream = Content.OpenStream("my-file.txt"); +// do something with file +stream.Close(); +``` + +## ContentManager.GetGraphicsDevice + +`GraphicsDevice ContentManager.GetGraphicsDevice()` + +**GetGraphicsDevice** returns the current `GraphicsDevice` from the services. + +```csharp +var graphicsDevice = Content.GetGraphicsDevice(); +var width = graphicsDevice.DisplayMode.Width; +``` + +# ContentReader extensions + +The `ContentReader` extensions help when writing your own content pipeline readers. + +## ContentReader.GetGraphicsDevice + +`GraphicsDevice ContentManager.GetGraphicsDevice()` + +**GetGraphicsDevice** returns the current `GraphicsDevice` to help when loading content for the current display. + +```csharp +public class MyTypeReader : ContentTypeReader { + protected override MyType Read(ContentReader reader, MyType existingInstance) + { + var graphicsDevice = reader.GetGraphicsDevice(); + // ... + } +} +``` + +## ContentReader.GetRelativeAssetName + +`string ContentReader.GetRelativeAssetName(string relativeName)` + +**GetRelativeAssetName** helps when your content type loads a different type, and you want to know the name to give `ContentManager.Load`. + + +```csharp +public class MyTypeReader : ContentTypeReader { + protected override MyType Read(ContentReader reader, MyType existingInstance) + { + var assetName = reader.GetRelativeAssetName(reader.ReadString()); + var other = reader.ContentManager.Load(assetName); + // ... + } +} +``` + diff --git a/mkdocs.yml b/mkdocs.yml index cfe9bfc9..4122af78 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,6 +12,7 @@ pages: - Core: - BitmapFonts: MonoGame.Extended/BitmapFonts.md - Camera2D: MonoGame.Extended/Camera2D.md + - Content Extensions: MonoGame.Extended/Content.md - Collections: MonoGame.Extended/Collections.md - Object Pooling: MonoGame.Extended/Object-Pooling.md - Screens: MonoGame.Extended/Screens.md