Game Development Reference
In-Depth Information
@implementation Trigger
{
BOOL _repeatsForever;
}
-(void) didLoadFromCCB
{
if (targetArrays == nil)
{
targetArrays = [NSMutableDictionary dictionary];
triggerArrays = [NSMutableDictionary dictionary];
}
[targetArrays removeAllObjects];
[triggerArrays removeAllObjects];
_repeatsForever = (_triggerCount <= 0);
}
@end
At first, two
static NSMutableDictionary
variables are declared. The keyword
static
means these variables will be shared with all instances of the
Trigger
class.
Essentially, they are global variables, but because they are declared in the scope of the im-
plementation file they are accessible only to code in the
Trigger.m
file.
The
@implementation
section declares an ivar
_repeatsForever
, which will be
used to determine whether this particular trigger instance will never remove itself.
The
didLoadFromCCB
method contains initialization and cleanup code for the two
global dictionaries. If
targetArrays
is
nil
, it will create an
NSMutableDiction-
ary
instance and assign it. The same is done for
triggerArrays
because it can
simply be assumed that if
targetArrays
is nil then
triggerArrays
will be nil, too.
Next, both dictionaries are instructed to
removeAllObjects
. That's kind of odd on
first sight, right?
Here's to foresight: eventually you'll be able to change levels. Given that the two diction-
aries are global (
static
) variables, they and their contents will remain in memory as
you switch levels and present other scenes. So in every new level that contains at least one
Trigger instance, those dictionaries need to be cleared of any remaining references.
Search WWH ::
Custom Search