Cocos2D isTouchEnabled = NO;场景释放和崩溃
我正在使用 cocos2d 开发一款 iPhone 游戏,而且我对 Objective C 和 Cocos2d 很陌生,所以如果这是一个真正的初学者问题,我很抱歉。我做了很多搜索,但似乎找不到解决这个问题的方法。我发现 cocos2d 不会调用 dealloc 函数,释放场景或图层,除非我将 -(void) onExit{self.isTouchEnabled = NO;}
放在 的末尾>.m
文件。问题是,在下一个场景中,即使我将 self.isTouchEnabled = YES;
放在 init
方法中,当触摸屏幕时游戏也会崩溃,onEnter
方法,或第二个场景中的任何其他地方。
当游戏崩溃时(gbd)指向:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if( 调度事件 ) [自我触摸:触摸withEvent:事件withTouchType:kCCTouchBegan]; }
作为问题的根源,指出“EXC_BAD_ACCESS”
请帮忙!!谢谢你!!
I'm working on an iPhone game using cocos2d and I'm new to Objective C and Cocos2d so I'm sorry if this is a really beginner question. I've done a lot of searching and I can't seem to find a solution for this problem. I've found that cocos2d will not call the dealloc function, release a scene, or a layer unless I put -(void) onExit{self.isTouchEnabled = NO;}
at the end of the .m
file. The problem is that in the next scene the game crashes when the screen is touched, even if I put self.isTouchEnabled = YES;
in the init
method, onEnter
method, or anywhere else within the second scene.
When the game crashes (gbd) points to:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if( dispatchEvents )
[self touches:touches withEvent:event withTouchType:kCCTouchBegan];
}
as the source of the problem stating "EXC_BAD_ACCESS"
Please help!! Thank you!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也是 iPhone 新手:-) 但根据我的经验,你得到“EXC_BAD_ACCESS”的原因并不是因为你在这里的代码。应该是“发布”问题。我猜你释放了一个已释放的对象...
你可以尝试使用 Xcode 的 Zombies 工具来检测你在哪里遇到这个问题。网上有很多关于 Xcode Zombies 的教程,如果你想要的话,只需 google 一下即可。
祝你好运:-)
I am new to iPhone as well:-) But for my experiences, the reason you get "EXC_BAD_ACCESS" is not because of your code here. it should be "release" problem. i guess you release a released object...
you can try to use Xcode's Zombies instruments to detect where you get this problem. There are heaps of tutorials about Xcode Zombies online, just google it if you want.
good luck:-)