Game Development Reference
In-Depth Information
4.4U SER I NTERFACE E LEMENTS
We will refer to user interface elements to all those features that are more complex and not
entirely suitable to be developed as controls. Features like health bars, radars, counters may
becreated usingavariety ofcontrols,butoftenrequiremorespecialized codetocommunic-
ate with the different game systems.
The base class for our game user interfaces will be the element . It will contain the main in-
terface by which we can group and iterate over a collection of elements that make up any
type of game user interface. A heads-up display (HUD) will consist of a variety of elements
each ofwhich will haveauniquepurpose,yetwill share acommon interface totake advant-
age of object oriented design. In particular, we will use a Model View Controller (MVC)
pattern which will allow us to separate the data from the player's control and its visual rep-
resentation.
class element
{
public:
element()
: m_view(nullptr)
, m_controller(nullptr)
{
}
virtual ~element()
{
m_view = nullptr;
m_controller = nullptr;
m_core = nullptr;
}
virtual void Create(std::shared_ptr<core_ui> core);
virtual void Update(float deltaTime);
virtual void Draw();
std::shared_ptr<core_ui> GetCore() const { return m_core; }
protected:
std::unique_ptr<view> m_view;
std::unique_ptr<controller> m_controller;
std::shared_ptr<core_ui> m_core;
};
Search WWH ::




Custom Search