Game Development Reference
In-Depth Information
}
}
return control::HandleInput(deltaTime, inputState);
}
void button::ChangeStateTo(eState state, bool invokeEvent)
{
m_state = state;
if ( invokeEvent )
{
switch (state)
{
case Default:
m_onReleased.Invoke(this, *this);
break;
case Pressed:
m_onPressed.Invoke(this, *this);
break;
}
}
if ( m_sprite != nullptr )
{
m_sprite->Play(state);
}
}
Using Sprite animations we can display the different states of a button, this allows us to
create a single spritesheet for a given button that contains animated version of each of the
button'sstate. Whenwecall ChangeStateTo weplaytheanimation forthat particular state,
whether it's the Default , Pressed , Disabled or any other custom state your buttons may
have.
m_button = std::unique_ptr<ui::button>(new ui::button(m_element.GetCore(), m_spriteFont, m_spriteBatch));
m_button->SetSize(math::vector2(160.f, 160.f));
m_button->SetPosition(math::vector2(10.f, 10.f), control::Pixels);
m_button->SetText(L"Start Game!");
m_button->OnReleased() += [&](const ui::button&) { StartGame(); };
Creating a button is fairly straightforward, initialize it to the desired position, size and
provide the desired behaviors on pressed or on released.
4.3.6 Text Boxes
Text boxes are the way to allow data entry through a keyboard, and their behavior is well
understood at this point, so when they are poorly implemented they can be a source of an-
noyance and frustration.
A text box must first, allow text entry of course, this means that when you type on a
physical keyboard or a virtual one on a portable device, the key you tapped must imme-
diately display the corresponding character within it. Next, typing must be instantaneous,
Search WWH ::




Custom Search