Game Development Reference
In-Depth Information
To implement such a system, we can introduce two new base classes. An Event
class, which is the base class for all event message types, and an EventHandler class,
which contains a single virtual method called Execute that will be called in order to
respond to an Event.
At its most basic level, the Event class will just contain a single member that is used
as a unique identifier for a particular type of event, for example, an enumerated type.
We can declare our own event types by deriving them from an Event and adding
members for any information we might want to pass along with the message. For
example, a touch screen event might contain the screen coordinates of where the
touch occurred.
Any class that wants to respond to a particular event can then derive from the
EventHandler class and provide an implementation for the virtual method. When a
new instance of a class is constructed, it registers its interest in any event by passing
the unique identifier of the event and a pointer to itself (cast as an EventHandler
pointer) to the event handler.
Now, whenever an event occurs we create an instance of the event type in question,
populate its members with information about that event, and pass it to the event
manager. The event manager will compare the unique identifier of the event against
its list of registered instances and then call the Execute method of EventHandler
for any of registered instance that wanted to be notified about the type of event that
has just occurred. The event message will be passed into the Execute method of the
instance so that its data can then be acted upon accordingly.
Screen resolution and orientation
Chances are that your game could well be executed on a number of different devices
that have different screen resolutions and aspect ratios, which can make creating a
nice looking user interface a real chore.
It is therefore important to provide a very flexible way in which the position and size
of UI controls can be specified.
When specifying screen coordinates, widths, and heights for controls, consider
allowing both exact pixel sizes and ratios of the width and height of the containing
frame to be used.
It is also good to allow a control to be conformed to a particular aspect ratio when
using ratios to define sizes. Being able to ensure that the control has a particular
aspect ratio makes it much easier to keep a consistent layout of any child control and
is particularly important when drawing bitmapped images that will look strange
if they end up stretched. When fixing a control to a particular aspect ratio, you will
want to be able to indicate whether the width or the height should change to keep
the control in the correct shape.
 
Search WWH ::




Custom Search