This class allows for easy texture placement inside text (each texture will be scaled vertically to match text line height, while maintaining original proportions).
Other functionalities are: shadow and simple "writing" animation.
textWithImages = new TextWithImages(spriteBatch: _spriteBatch, font: fontFreeSansBold, text: "This is a sample text | | | | .", imageList: new List<Texture2D> { imageUp, imageEnter, imageSpace, imageUp });
textWithImages.Update(); // place inside Update()
textWithImages.Draw(position: textPos, color: Color.White, textScale: 1f); // place inside Draw()
textWithImages = new TextWithImages(spriteBatch: _spriteBatch, font: fontFreeSansBold, text: "This is a sample text | | | | .",
imageList: new List<Texture2D> { imageUp, imageEnter, imageSpace, imageUp });
SpriteBatch: spriteBatch that will be used to render.
Font: font for text.
Text: text to write. Mark images with "|" character marker (marker count must match image count).
ImageList: list of Texture2D objects. Must match "|" marker count.
Animate: enable "writing" animation effect.
FramesPerChar: how many frames will every character be displayed for. Use with "animate".
CharsPerFrame: how many characters will be displayed for every frame. Use with "animate".
TreatImagesAsSquares: change image proportions to square (squashing them).
textWithImages.Update();
textWithImages.Draw(position: textPos, color: Color.White, textScale: 1f);
Position: upper-left text corner position.
Color: text color.
TextScale: whole text "block" scale (images included).
ImageOpacity: opacity of images (does not affect text).
InflatePercent: changes the size of every image (in place). Allows for big images, overlapping text.
ShadowColor: shadow color.
ShadowOffset: shadow offset.
TextWidth: text width. Does not account for "textScale" used in Draw(). Useful for calculating draw position.
TextHeight: text height. Does not account for "textScale" used in Draw(). Useful for calculating draw position.
TextOriginal: original text, that was inserted.
Text: modified text, with markers changed to spaces (to match image width properly).
NoOfLines: text line count.
AnimationFinished: has animation been finished. Always true if "animate" option is disabled.