【发布时间】:2014-02-23 23:45:36
【问题描述】:
我已经为此苦恼了一段时间。我知道在 cocos2d v3 中它发生了变化,因此只要您设置 contentSize 并设置 self.userInteractionEnabled = YES,CCNode 就可以接受触摸。
这对我不起作用。我有一个作为子节点添加到 CCScene 的 CCNode,但没有注册任何触摸。
这是 CCNode 代码:
-(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");
}
还有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];
我没有得到 touchBegan 函数的日志。难道我做错了什么?记住这是 cocos2d v3,关于这个版本的文档还不是很多:(
【问题讨论】:
-
嘿,我也遇到了同样的问题。你是怎么解决这个问题的?谢谢
标签: ios cocos2d-iphone