For some time now I hit my head about this. I know that in cocos2d v3 it has changed, so CCNode can take strokes while you set contentSize and set self.userInteractionEnabled = YES .
This does not work for me. I have a CCNode that I am adding as a child of CCScene, but any touch is not logged.
Here's the CCNode code:
-(id) initWithPortName:(NSString *)portName andDesc:(NSString *)desc { self = [super init]; if (!self) return(nil); CGSize winSize = [[CCDirector sharedDirector] viewSize]; self.contentSize = winSize; self.portName = portName; self.desc = desc; self.descLabel = [[CCRPGLabel alloc] initWithString:desc fontName:@"Arial" fontSize:18.0f dimensions:CGSizeMake(300, 150)]; self.descLabel.color = [CCColor blackColor]; self.descLabel.position = ccp(winSize.width/2, -200); [self addChild:self.descLabel]; return self; } - (void) onEnter { self.userInteractionEnabled = YES; [super onEnter]; } - (void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event { NSLog(@"here"); }
And CCScene:
self.portNode = [[MainPort alloc] initWithPortName:@"Santa Maria Port" andDesc:@"This port is soweeeet"]; self.portNode.position = ccp(0, winSize.height); self.portNode.contentSize = winSize; [self addChild:self.portNode];
I do not have a log for the touchBegan function. Am I doing something wrong? Remember that this is cocos2d v3, there is not much documentation on this version :(
source share