Game Development Reference
In-Depth Information
Note It may seem kind of inefficient to have every trigger removeAllOb-
jects when doing so once would suffice, but I find it's not enough to justify
adding extra code to check whether targetArrays and triggerArrays
are empty every time a Trigger instance is created. Whether you do that or
simply issue the removeAllObjects method for every instance amounts to
the same work anyway, but it'll be more code.
Finally, _repeatsForever is set to the result of _triggerCount being equal to or
less than 0. This means the trigger will be repeating if _triggerCount is initially 0 or
a negative value. This would be the case if you'd simply omit adding the trigger-
Count custom property in SpriteBuilder because ivars are initialized to 0.
Tip In Objective-C, all static variables and all ivars are always initialized to
0. For BOOL ivars, 0 equals NO ; for id and Objective-C class pointer variables,
0 equals nil . Furthermore, since automatic reference counting (ARC) is en-
abled in every SpriteBuilder project, each local variable of type id and
Objective-C class pointers are initialized to nil as well. The only variables you
have to assign a value before reading from them are local variables that are
primitive data types (i.e., BOOL , int , CGFloat , double , NSUInteger and
similar) and C structs and C pointers like void* .
This version of the project should build and run without errors, but triggers won't be func-
tional yet.
Finding Triggers and Targets
The next step is to collect a set of targets for each trigger. Triggers connect to targets
simply by using the same name for trigger and target nodes. Not only can there be mul-
tiple targets for a single trigger, there can also be multiple triggers of the same name activ-
ating the same target(s).
Finding and Storing Triggers
You should add Listing 5-8 to Trigger.m just above the @end line.
Search WWH ::




Custom Search