当我的 ccLayer 具有 loadNibNamed 时,如何识别 ccTouches 事件
我的问题是我没有找到通过 UIScrollView “刺穿”的解决方案,以便 ccLayer 可以识别 ccTouch 事件
self.isTouchEnabled = YES;
[[NSBundle mainBundle] loadNibNamed:@"myLayer" owner:self options:nil];
...
- (void) registerWithTouchDispatcher {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN swallowsTouches:NO];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertToWorldSpace:[self convertTouchToNodeSpace:touch]];
有什么想法如何创建委托或其他解决方案来绕过 UI 并与 cc 对话?
My problem is that I didn't find a solution to "pierce" through a UIScrollView so the ccLayer could recognize the ccTouch events
self.isTouchEnabled = YES;
[[NSBundle mainBundle] loadNibNamed:@"myLayer" owner:self options:nil];
...
- (void) registerWithTouchDispatcher {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN swallowsTouches:NO];
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint location = [self convertToWorldSpace:[self convertTouchToNodeSpace:touch]];
Any ideas how to create a delegate or another solution to bypass the UI and talk with the cc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
今天早上我在使用 Cocos2D v1.0.0 时遇到了这个问题。我的解决方案是在该层的 init 方法中包含 CCTouchDispatcher 方法调用,然后 UIView 内的该层将识别触摸。
另一种解决方案是使用 ccTouchesBegan 方法:
请注意,这两种触摸方法具有不同的方法来让您的应用程序知道它应该响应触摸。您无法混合搭配您想要响应触摸的方式以及您想要观察的触摸。
I had this problem this morning with Cocos2D v1.0.0. My solution was to include the CCTouchDispatcher method call inside my init method for the layer, and then that layer, inside a UIView, would recognize touches.
An alternative solution would be to use the ccTouchesBegan method:
Note that the two touch methods have different methods to let your application know it should respond to touches. You can't mix and match how you want to respond to touches, and which touches you want to observe.