小黑米的生活

只玩技术

[cocos2d] CCArray类

leave a comment

你可 以在Xcode项目中的cocos2d/Support组找到CCArray的类文件。cocos2d引擎内 部使用了CCArray。它和苹果官方的NSMutableArray类似,但是运行效率更高。 CCArray类实现了NSArray和NSMutableArray的子集,并且添加一些从NSArray初 始化到CCArray的新方法。CCArray通过将数组中的最后一个对象(nil)赋值给删 除的位置,实现了fastRemoveObject和fastRemoveObjectAtIndex两个方法。避 免了复制部份数组的内存。这让删除数组中的元素变的更快,不过这也意味着 CCArray中的对象会改变位置。如果你的程序依赖于指定的对象排列次序,你就 不应该使用fastRemoveObject这类方法。在列表4-9中,你可以看到CCArray的 类引用 – 它没有实现所有的NSArray和NSMutableArray方法:
列表4-9. CCArray的类引用

+ (id) array;
+ (id) arrayWithCapacity:(NSUInteger)capacity;
+ (id) arrayWithArray:(CCArray*)otherArray;
+ (id) arrayWithNSArray:(NSArray*)otherArray;
- (id) initWithCapacity:(NSUInteger)capacity;
- (id) initWithArray:(CCArray*)otherArray;
- (id) initWithNSArray:(NSArray*)otherArray;
- (NSUInteger) count;
- (NSUInteger) capacity;

- (NSUInteger) indexOfObject:(id)object;
- (id) objectAtIndex:(NSUInteger)index;
- (id) lastObject;
- (BOOL) containsObject:(id)object;
#pragma mark Adding Objects
- (void) addObject:(id)object;
- (void) addObjectsFromArray:(CCArray*)otherArray;
- (void) addObjectsFromNSArray:(NSArray*)otherArray;
- (void) insertObject:(id)object atIndex:(NSUInteger)index;
#pragma mark Removing Objects
- (void) removeLastObject;
- (void) removeObject:(id)object;
- (void) removeObjectAtIndex:(NSUInteger)index;
- (void) removeObjectsInArray:(CCArray*)otherArray;
- (void) removeAllObjects;
- (void) fastRemoveObject:(id)object;
- (void) fastRemoveObjectAtIndex:(NSUInteger)index;
- (void) makeObjectsPerformSelector:(SEL)aSelector;
- (void) makeObjectsPerformSelector:(SEL)aSelector withObject:(id)object; - (NSArray*) getNSArray;

原创文章,转载请注明: 转载自小黑米的生活

本文链接地址: [cocos2d] CCArray类

Written by edwardhey

十月 4th, 2011 at 4:56 下午

Leave a Reply

无觅相关文章插件,快速提升流量