Game Development Reference
In-Depth Information
Listing 4-1. CGGeometry.h (CGRect, CGPoint, and CGSize)
/* Points. */
struct CGPoint {
CGFloat x;
CGFloat y;
};
typedef struct CGPoint CGPoint;
/* Sizes. */
struct CGSize {
CGFloat width;
CGFloat height;
{
CGPoint origin;
CGSize size;
its parent. These structs are defined in the file CGGeometry.h , which is part of the Core Graphics
framework, a standard part of any iOS project. Notice that x , y , width , and height values are defined
as CGFloat . The unit for these values is points, not pixels. The difference is subtle at first, but the
idea here is that the coordinates and sizes you are specifying with these values is meant to be
resolution independent. Further discussion of points vs. pixels can be found in Appendix A.
Tip The letters CG in the names of structs such as CGRect refer to the Core Graphics framework. So
a CGRect is referred to as a Core Graphics Rect when you want to be precise.
To create any of the base geometric types from Listing 4-1, an inline utility function is defined in
CGGeometry.h , as seen in Listing 4-2.
Listing 4-2. CGGeometry.h (CGPointMake, CGSizeMake, and CGRectMake)
/*** Definitions of inline functions. ***/
CG_INLINE CGPoint
CGPointMake(CGFloat x, CGFloat y)
{
CGPoint p; p.x = x; p.y = y; return p;
}
 
 
Search WWH ::




Custom Search