i have a subclassed CCNode to which I add several of the same small subclassed CCSprite WHICH IN TURN have several subclassed sprite children. I thought I was using CCSpriteBatchNode properly but I'm noticing hundreds of draw calls are registering and I thought this should only be ONE.
My CCNode subclass adds this child:
Segment* segment = [Segment segmentWithState:kState];
[self addChild:segment];
The segment is a subclass of CCSprite with:
+(id) segmentWithState:(SegmentState)segmentState { return [[self alloc] initWithState:segmentState];}
-(id) initWithState:(SegmentState)theSegmentState {
segmentSpriteBatch = [CCSpriteBatchNode batchNodeWithFile:@"txt.png"];
[self addChild:segmentSpriteBatch];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"txt.plist"];
self = [super initWithSpriteFrameName:theSegmentStateFrameName];
if (self){
Subsegment * subsegment = [Subsegment subsegmentWithState:kInvisible];
}
return self;
Then this segment subclass gets a child of the subclass subsegment which has the same code:
+(id) subsegmentWithState:(SubsegmentState)subegmentState { return... ]
-(id) initWithState:(SubsegmentState)theSubsegmentState {
subegmentSpriteBatch = [CCSpriteBatchNode batchNodeWithFile:@"txt.png"];
[self addChild:subegmentSpriteBatch];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"txt.plist"];
self = [super initWithSpriteFrameName:theSubegmentStateFrameName];
if (self){
}
return self;
I tried adding one batch node to the CCNodeSUbclass and then adding an instance of a segment as a child to batchnode but this throws an error. I'm also not sure how i'd then add the children (subsegments) the the CCNodesubclass batchnode.
incidentally, is my use of classes rather than instance methods code smell that is coming to light with this?