Game Development Reference
In-Depth Information
needsViewUpdated = YES;
}
}
-(void)addBehavior:(NSObject<Behavior>*)behavior{
if (behaviors == nil){
behaviors = [NSMutableArray new];
}
[behaviors addObject:behavior];
}
+(CGPoint)randomPointAround:(CGPoint)aCenter At:(float)aRadius{
float direction = arc4random()%1000/1000.0 * M_PI*2;
return CGPointMake(aCenter.x + cosf(direction)*aRadius, aCenter.y + sinf(direction)*aRadius);
needsViewUpdated to YES when these values change. This is done to ensure that the actor's
updates the UIView representing this actor when the actor's state or variant property
initAt:WithRadius:AndRepresentation : simply initializes the actor and sets the passed-in
Working with the Power-Up Actor
In the previous section, we looked at the classes GameController and Actor and learned that the
Actor class requires a Representation object to be displayed. The Representation protocol describes
what is required of a class to manage the UIView associated with an actor. In this section, we will
explore the class ImageRepresentation and see how it uses images to represent an actor. In the
preceding chapter, we used images to draw different actors. In this section, we will show how we
can combine those techniques into a simple, reusable class called ImageRepresentation .
To illustrate ImageRepresentation , in our first example we will create power-ups and animate them
across the screen, as shown in Figure 6-1 .
 
Search WWH ::




Custom Search