Game Development Reference
In-Depth Information
public:
std::wstring Text;
DirectX::XMFLOAT2 Position;
DirectX::XMFLOAT4 Color;
TextBlock() : Text(L""), Position(0, 0),
Color(DirectX::Colors::White) {};
};
Now we need to add a
SpriteFont
, and a vector of
TextBlocks
to the
Render-
remember that we need the path, so we need to add a new parameter to Initialize,
and then set that to the path of our
.font
file. We'll also create a new helper method
in Renderer named
CreateText
that creates a new
TextBlock
and adds it to the
TextBlock
vector.
Now add the following code to the
Draw
method, after you draw the sprites (but be-
fore you call
_sb->End()
:
for (auto text : _text)
{
auto colVec =
DirectX::XMLoadFloat4(&(text->Color));
_font->DrawString(_sb.get(),
text->Text.data(), text->Position, colVec);
}
Once we have that we can add some code to the
Draw
method before we end the
SpriteBatch
to draw each item in the
TextBlock
vector using the stored data.
Now let's return to the
Game
class in Game.cpp.
_scoreText =
Renderer::GetInstance()->CreateText();
_scoreText->Position.x =
m_renderTargetSize.Width - 500;