Game Development Reference
In-Depth Information
the game, as well as the basic setup so we can focus on networking later on. If you
want to jump to the networking part of this chapter, feel free to skip this section. Here
we'll look at one kind of implementation that you could use.
Right now we just have a way to display text using some TextBlock objects that
we can add to the renderer; however, even just switching between the score display
and the game over message requires a bit of coding work to remove and add the text
blocks one-by-one, as well as store their state individually. To get around this we're
going to create a menu object that can store the state of the menu and allow us to
easily construct and change menus. For the purposes of the sample we only need
text functionality; however, this can also let you display textures for the different UI
elements, allowing you to create a richer user interface.
For this system we have three classes: Menu , ControlBase , and TextBlock (in-
side Menu.h , ControlBase.h , and TextBlock.h ). The ControlBase is an ab-
stract class with the following definition:
enum class FocusState
{
Unfocused,
Focused
};
class ControlBase abstract
{
protected:
bool _isVisible;
DirectX::XMFLOAT2 _pos;
Placement _placement;
bool _canFocus;
public:
virtual void
Draw(std::shared_ptr<SpriteBatch> spriteBatch,
FocusState focused) = 0;
virtual void HandleClick() = 0;
virtual bool PointInBounds(float x, float y)
= 0;
Search WWH ::




Custom Search