# Using CAShaperLayer within COCOS2d

My class X is interited from CCLayer.

@interface X : CCLayer

Then in X, I added an instance variable of type CAShapeLayer.

CAShapeLayer *_Circle

I drew the Circle using UIBezierPath. Now if I try to add _circle to self, it gives me error:

[self addChild:_Circle];

[CAShapeLayer tag]: unrecognized selector sent to instance 0x916f7f0 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAShapeLayer tag]: unrecognized.


I also tried typecasting _Circle to (CCNode*) or (CCSprite*) but nothing helped.

Any suggestions?

• CAShapeLayer is a class. Try [_Circle tag];. – ott-- Jul 15 '13 at 9:27
• No, I am not adding [CAShapeLayer tag] myself. It is coming as a run time exception. My statement is [self addChild:_Circle]; The problem is addChild expects CCSprite or CCNode object but CAShapeLayer isn't that. I am not sure how CAShapeLayer can be used inside cocos2d scenes. – ganesh Jul 16 '13 at 0:16
• Is that @interface X : CCLayer a typo? (CALayer?). And isn't it the other way round, first you create a layer and a sublayer, then you draw a spline between them? See developer.apple.com/library/mac/#documentation/GraphicsImaging/… – ott-- Jul 16 '13 at 9:01
• CCLayer is a class for layer drawing in COCOS2d. It's not native class. I saw few people suggesting to use CALayer in COCOS2d to animate primitive shapes like circle in my case. I want to programmatically draw a circle and then animate it's drawing on screen. Basically only part of circle will be drawn based on some input value like 60% or 80% and draw should be animated. I have implemented it in CALayer individually but not able to integrate with COCOS2d layers or sceens. – ganesh Jul 17 '13 at 20:27