Game Development Reference
In-Depth Information
spriteBatch->Draw(*texture->GetView(), m_rectangle, nullptr, m_color);
}
The size ofthe caret isoften oneortwopixels wide, andthe height isfont-dependent; 80%
of the font's line spacing as height, with a padding of 10% from the top will generate a
pleasing result.
Alternatively, as we will see later in Animation with Interpolation Curves , we could re-
place the code that handles the blink timer/duration with an animation.
void caret::Update(float deltaTime)
{
m_interpolator.Update(deltaTime);
animation caretAnimation(m_color.A(),
m_toggle ? 1.f : 0.f,
0.25f,
curves::ease_in_out<curves::linear>,
[&] { m_toggle = !m_toggle; } );
if ( m_interpolator.ActiveAnimationCount() == 0 )
{
m_interpolator.Add(caretAnimation);
}
These few lines of code replace the timer and duration variables we were keeping around
only for the blinking of the caret. Instead, what we do is through an interpolator, we create
an animation that when m_toggle is true it will animate m_color's alpha value towards 1.0
attherateof4timespersecond.Oncetheanimationiscomplete,weflip m_toggle through
a lambda function, the next animation we create will animate the alpha value of m_color
back towards 0.
4.3.6.2Auto Completion
It's a good idea to implement auto completion for text boxes that expect user input, it sim-
plifies text entry and nowadays from the behavior of web browsers and other software we
have become used to it, there is no reason not to provide the same functionality within our
games when appropriate.
Search WWH ::




Custom Search