Game Development Reference
In-Depth Information
In Figure 4-2 , you can see in the back the root UIWindow for our sample application. When the user is
seeing the game view, the UIWindow has a single subview, which is the view property associated with
the GameController class. The GameController places the Portrait Play view as a subview of its view
when the user clicks the New Game button. The Portrait Play view has five subviews, as defined in
the XIB file. Four of these subviews are UILabel s for displaying and tracking the user's score and
remaining turns. The fifth UIView is the Portrait Game Holder view, which is responsible for defining
the region where the view from the CoinsController is placed. The view from the CoinsController
has several subviews, which make up the interactive part of the game. You will be looking at those
views in more detail later, but for now, understand that those views are added to the scene in exactly
the same way as the rest of the views.
Another thing to notice about Figure 4-2 is that not all of the views are placed in the same position
relative to their parent. For example, the Portrait Play view is placed at the upper left of the
GameController view, while the Portrait Game Holder view is placed about halfway down its parent,
the Portrait Play view. The property frame of the subview dictates where it is placed relative to its
parent. Figure 4-3 shows this in more detail.
Parent UlView
frame.size.width
frame.origin,x,y
frame.size.height
Sub UlView
Figure 4-3. The frame of a UIView
As shown in Figure 4-3 , the frame of a UIView describes not only the location of a subview, but also
the size of the view. Generally speaking, the frame is said to describe the region of a subview. The
property frame is a struct of type CGRect and is composed of two other structs, origin and size . The
field origin is of type CGPoint and describes the location of the upper-left corner of the subview in
terms of points. The field size is of type CGSize and describes the number of points the subview is
wide and high.
Core Graphics Type Definitions
Core Graphics defines a number of types, structs, and functions. These include the previously
mentioned CGRect , CGpoint , and CGSize . Listing 4-1 shows the definitions of these three structs.
 
Search WWH ::




Custom Search