Game Development Reference
In-Depth Information
Listing 7-7. VectorRepresentation.h
#import <Foundation/Foundation.h>
#import "Actor.h"
@class VectorActorView;
@protocol VectorRepresentationDelegate
-(void)drawActor:(Actor*)anActor WithContext:(CGContextRef)context InRect:(CGRect)rect;
@end
@interface VectorRepresentation : NSObject<Representation> {
VectorActorView* view;
}
@property (nonatomic, assign) NSObject<VectorRepresentationDelegate>* delegate;
+(id)vectorRepresentation;
@end
In Listing 7-7, we see that the class VectorRepresentation defines a protocol called
VectorRepresentationDelegate to which each vector-based actor must conform. This protocol
requires the task drawActor:WithContext:InRect: to be implemented by all classes that conform to
it, and is where the actual drawing code should be placed.
The class VectorRepresentation extends NSObject and conforms to the protocol Representation ,
just like the class ImageRepresentation does. The idea here is that most of the code should not care
which type of representation we use—vector or image. We simply create the correct Representation
object and associate it with each actor.
We also see that the class VectorRepresentation has a single property view of type
VectorActorView . A VectorActorView is a subclass of UIView and will ultimately call the task
drawActor:WithContext:InRect: as defined by the protocol VectorRepresentationDelegate .
Before looking at the class VectorActorView , let's look at the implementation of
VectorRepresentation as shown in Listing 7-8.
Listing 7-8. VectorRepresentation.m
#import "VectorRepresentation.h"
#import "VectorActorView.h"
@implementation VectorRepresentation
@synthesize delegate;
+(id)vectorRepresentation{
return [VectorRepresentation new];
}
-(UIView*)getViewForActor:(Actor*)anActor In:(GameController*)aController{
if (view == nil){
view = [VectorActorView new];
[view setBackgroundColor:[UIColor clearColor]];
[view setActor: anActor];
Search WWH ::




Custom Search