cocos2d 在第二个场景中启用触摸
我有带按钮的菜单 当触摸播放按钮时 游戏转到另一个场景 但触摸在那里不起作用 我写 self.isToucheEnabled=YES; 在初始化方法中 并在onEnter方法中添加 [[CCTouchDispatcher sharedDispatcher] setDispatchEvents:YES];
但这行不通 请帮助我为什么可以启用触摸
i have menu with buttons
when touch the Play button
game go to another scene
but Touch don't work there
i'm write
self.isToucheEnabled=YES;
in init method
and add in onEnter method
[[CCTouchDispatcher sharedDispatcher] setDispatchEvents:YES];
but that don't work
pleas help why i can enable touch
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您必须输入以下代码:
-(void) onEnter {
[[CCTouchDispatcher共享Dispatcher] addTargetedDelegate:自身优先级:0燕子触摸:是];
}
在您想要启用 TouchDispatcher 的场景中,然后在同一场景中确保输入以下内容:
-(void) onExit {
[[CCTouchDispatchersharedDispatcher]removeDelegate:self];
}
并且触摸应该在包含上述代码的每个场景中注册。
You must put the following code:
-(void) onEnter {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
inside the scene you want to enable the TouchDispatcher on, then in the same scene make sure you enter this:
-(void) onExit {
[[CCTouchDispatcher sharedDispatcher] removeDelegate: self];
}
and the touch should register in every scene that you have the above code in.
这是如何在 cocos2d 中定义菜单的示例 (来源):
如果您需要更多帮助,请提供您用于创建菜单的代码。
This is an example of how you define a menu in cocos2d (source):
If you need more help, please provide the code that you are using to create the menu.
您还必须在标头的 CCLayer 中添加 UIGestureRecognizerDelegate 接口!
例如:
You also have to add UIGestureRecognizerDelegate interface in your CCLayer in your header!
e.g.:
在层中使用:-(
void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
不:-(
BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
In the layer use:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Not:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event