I've been beating my head over this for a while now. I know in cocos2d v3 it changed so that CCNode can accept touches as long as you set the contentSize
and set self.userInteractionEnabled = YES
.
This is not working for me. I have a CCNode that I add as a child to a CCScene, but any touch is not getting registered.
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 the 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 get no log for the touchBegan
function. Am I doing something wrong? Remember this is cocos2d v3, not much documentation on this version yet :(