gpt4 book ai didi

ios - CCNode 作为 CCScene 触摸处理程序 cocos2d v3 的子项

转载 作者:可可西里 更新时间:2023-11-01 03:56:01 24 4
gpt4 key购买 nike

我已经为此苦思冥想了一段时间。我知道在 cocos2d v3 中它发生了变化,因此只要您设置 contentSize 并设置 self.userInteractionEnabled = YES,CCNode 就可以接受触摸。

这对我不起作用。我有一个 CCNode,我作为 child 添加到 CCScene,但没有注册任何触摸。

这是 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,关于这个版本的文档还不多:(

最佳答案

在 CCResponderManager.m touchesBegan:withEvent: 中设置断点:

它循环遍历所有启用了 userInteractionEnabled 的 CCNode 并检查命中。您可以做的第一件事是查看您的 objective-c CNode 是否在 _responderList 中。如果是,您可以跟踪到该 CCNode 的 hitTestWithWorldPos: 并查看它返回 false 的原因。

关于ios - CCNode 作为 CCScene 触摸处理程序 cocos2d v3 的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21976350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com