Game Development Reference
In-Depth Information
custom property timelineName of type String that allows you to specify the name
of the Timeline to be played. Refer to Figure 4-2 and Figure 4-3 if you don't remember
how to add custom properties to a node.
Let's move on to the PlayTimelineWhenTriggered.m , shown in its entirety in
Listing 5-16 . I suppose I needn't say this anymore: make your
PlayTimelineWhenTriggered.m look like the one in Listing 5-16 .
Listing 5-16 . Playing a Timeline when triggered
#import "PlayTimelineWhenTriggered.h"
@implementation PlayTimelineWhenTriggered
-(void) didLoadFromCCB
{
if (_timelineName.length == 0)
{
_timelineName = @"Default Timeline";
}
}
-(void) didTriggerWithNode:(CCNode*)activator
{
[self.animationManager
runAnimationsForSequenceNamed:_timelineName];
}
@end
The didLoadFromCCB method is used to assign the @"Default Timeline" string
to _timelineName if _timelineName is initially either an empty string or nil . The
_timelineName ivar is automatically created by the compiler just by adding the
@property to the class' @interface . The didTriggerWithNode: method plays
the animation specified by _timelineName when a Trigger activates it.
Quite simple, isn't it? You will probably need to create many variants of classes imple-
menting the TriggerDelegate protocol to perform all kinds of different things when
triggers are activated. But for each class, you should strive to use custom properties to al-
low yourself or your team to alter the class' behavior.
If you publish, build, and run the app and move the player into a trigger area that activates
the Saw1_noautoplay.ccb , it will crash.
Search WWH ::




Custom Search