在使用cocos2dx的重力感应代码时。在iOS环境下测试,发现经常对重力感应的反应的有问题。
我在每一局开始的时候,切换新的scene,在新的scene中打开重力感应并增加监听。代码和cocos2dx的test代码一样。
但在实际使用中。有时候很正常。多玩两局就出问题了,有时候是反应不灵敏,有时候反应是上下相反。有时候控制的对象会快速移动很长的距离。
感觉好像是和ios的屏幕翻转冲突了。
我在ios/RootViewController.mm修改了锁定屏幕方向的代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//return UIInterfaceOrientationIsLandscape( interfaceOrientation );
//锁定屏幕方向
return interfaceOrientation == UIInterfaceOrientationPortrait;
}
但是程序运行还是有同样的问题。
困扰很久了,找了很多方法都不行。
在线等高手答案。