Game Development Reference
In-Depth Information
[view setDelegate:delegate];
[anActor setNeedsViewUpdated:YES];
}
return view;
}
-(void)updateView:(UIView*)aView ForActor:(Actor*)anActor In:(GameController*)aController{
if ([anActor needsViewUpdated]){
[aView setNeedsDisplay];
[anActor setNeedsViewUpdated:NO];
}
}
@end
VectorRepresentation
and that it has a trivial
getViewForActor:In:
and
updateView:In:
Representation
. In the task
getViewForActor:In:
we create a new
, and specify the actor and delegate that should be used to draw. Then we call
, making sure the actor's drawing code is called at least once.
updateView:In:
we check to see if the actor needs updating; if so, we call
on the
UIView aView
. The task
setNeedsDisplay
is defined by the class
UIView
UIView
should be redrawn. In effect,
drawRect:
task of our
VectorActorView
to be called, which in turn will call the
of our actor. Next we want to look at the details of the class
.
A UIView for Vector-Based Actors: VectorActorView
The class
VectorActorView
is a subclass of
UIView
and is used to represent the actor in the scene in
much the same way as we use
UIImageView
instances to represent image-based
Actor
s. Let's take
a look at the class
VectorActorView
and see how it all fits together, starting with the header. See
Listing 7-9.
Listing 7-9. VectorActorView.h
#import <UIKit/UIKit.h>
#import "Actor.h"
#import "VectorRepresentation.h"
@interface VectorActorView : UIView {
}
@property (nonatomic, retain) Actor* actor;
@property (nonatomic, retain) NSObject<VectorRepresentationDelegate>* delegate;
@end
In Listing 7-9, we see that
VectorActorView
extends
UIView
and has two properties. The first is
the
Actor
that is to be drawn. The second property is the
VectorRepresentationDelegate
that