Game Development Reference
In-Depth Information
{
[trigger.parent removeFromParent];
}
[targetArrays removeObjectForKey:_name];
[triggerArrays removeObjectForKey:_name];
}
}
The updateTriggers: method simply reduces the triggerCount property of each
trigger by one. It assumes that all triggers of the same name start with the same trig-
gerCount ; otherwise, some triggers may trigger more often than others, which is prob-
ably not what you want. Specifically, it doesn't allow you to combine Trigger-
Once.ccb and TriggerForever.ccb to trigger the same targets. If that's what you
need, you would have to update cleanupTriggers: so that it only removes triggers
whose triggerCount has reached 0 and where the trigger isn't set to repeat forever.
The cleanupTriggers: method then tests the current trigger's _triggerCount ,
which has just been decreased. If it is 0 or less, it can be assumed that all the triggers have
done their job and can be removed. As I said earlier, each trigger is the child of a
CCNode, the root node of the TriggerOnce.ccb , so it is best to remove the trigger's
parent by sending it the removeFromParent message. Removing the parent will also
remove any child nodes, including the trigger node itself.
Considering that these triggers have done their job, neither the targets' nor the triggers'
NSPointerArray are needed anymore. Hence, they are being removed from the tar-
getArrays and triggerArrays .
Informing Triggers About Collisions
What's left at this point is to actually send the triggerActivatedBy: message to a
Trigger instance on collision, and implement a class that conforms to the Trigger-
Delegate protocol that then runs custom code when its didTriggerWithNode: se-
lector runs.
This is where the Collision type of the color node in the TriggerOnce.ccb
comes into play. You've set this field to trigger . Therefore, you should add a collision
method to GameScene.m whose third parameter is named trigger .
Add the code in Listing 5-14 at the end of GameScene.m , just above the @end
keyword.
Search WWH ::




Custom Search