Game Development Reference
In-Depth Information
Let's use a proper
@property
this time because you may possibly want to access or
change this value at runtime from other classes. Open
Trigger.h
and add the
@prop-
nodes need to implement. Also, add the declaration of the
triggerActivatedBy:
method.
Listing 5-6
.
Adding the triggerCount property to Trigger.h
#import "CCNode.h"
@protocol TriggerDelegate <NSObject>
-(void) didTriggerWithNode:(CCNode*)activator;
@end
@interface Trigger : CCNode
@property int triggerCount;
-(void) triggerActivatedBy:(CCNode*)activator;
@end
This allows you to run the project without errors, although the trigger itself doesn't work
yet.
Programming the Trigger Class
The
Trigger.m
implementation will be a tad more complex, but it's also a reusable
class that you may want to use in your own projects. It collects all the trigger and target
nodes upon loading. The
Trigger
class forwards the trigger collision event to all target
nodes, updates the
triggerCount
and, if necessary, removes the trigger nodes when
they are no longer needed.
Initializing Trigger and Target Arrays
Listing 5-7
.
Trigger implementation initializing trigger and target storage dictionaries
#import "Trigger.h"
static NSMutableDictionary* targetArrays;
static NSMutableDictionary* triggerArrays;
Search WWH ::
Custom Search