Game Development Reference
In-Depth Information
Listing 5-8 . Storing the trigger and target nodes in onEnter
-(void) onEnter
{
[super onEnter];
self.parent.visible = NO;
NSAssert1(_parent.name.length > 0, @"Trigger node has
no name: %@", self);
self.name = _parent.name;
NSPointerArray* triggers = [triggerArrays
objectForKey:_name];
if (triggers == nil)
{
triggers = [NSPointerArray weakObjectsPointerArray];
[triggerArrays setObject:triggers forKey:_name];
}
[triggers addPointer:(void*)self];
if ([targetArrays objectForKey:_name] == nil)
{
NSPointerArray* targets = [NSPointerArray
weakObjectsPointerArray];
[targetArrays setObject:targets forKey:_name];
[self addTargetsTo:targets searchInNode:self.scene];
NSAssert1(targets.count > 0, @"no target found for
trigger named '%@'", _name);
}
}
Notice that you can't use didLoadFromCCB to find all triggers and targets; instead, you
have to use onEnter . Since didLoadFromCCB runs immediately after each individual
node has been loaded, there likely will be target or trigger nodes that haven't been loaded
yet if you were to run the code in Listing 5-8 in didLoadFromCCB . The soonest you
can start searching for all target and trigger nodes in the node hierarchy is when
onEnter runs. The onEnter method is sent to each node instance after it has been ad-
ded as a child to another node.
Search WWH ::




Custom Search