Game Development Reference
In-Depth Information
NSMutableArray* spiders;
float spiderMoveDuration;
int numSpidersMoved;
}
Caution Avoid using CCArray in your own code. CCArray is a faster re-
placement for NSArray and NSMutableArray . But it's only marginally
faster and using it will hardly affect framerate in almost all cases. Some meth-
ods like insertAtIndex or removeObjects are significantly slower than
the same methods of NSMutableArray . The biggest problem with CCAr-
ray is that it's been shown to have critical bugs in the past, including ARC-
compatibility issues. It also doesn't support all the features of NSAr-
ray / NSMutableArray . For example, you can't enumerate a CCArray with
blocks, which makes it unsuitable for concurrent processing (via Grand Central
Dispatch, for example). Overall, CCArray is simply not as reliable, compat-
ible, or defect-free as NSMutableArray is. I would trade performance any
time for reliability. Cocos2d uses CCArray internally, and for internal uses
CCArray has been proven and well tested. I would leave it at that.
And in the GameLayer init method, add the call to the initSpiders method
discussed next, right after scheduleUpdate :
-(id) init
{
if ((self = [super init]))
{
...
[self scheduleUpdate];
[self initSpiders];
}
return self;
}
After that you add a fair bit of code to the GameLayer class, beginning with the
initSpiders method in Listing 4-8 , which is creating the spider sprites.
 
Search Nedrilad ::




Custom Search