各位高手,请问一下cocos2d-x这个引擎如何改变设备的方向呢?cocos2d可以调用 setDeviceOrientation函数修改,但是cocos2d-x引擎并没有这个方法,请教一下如何解决这个问题,多谢!!

解决方案 »

  1.   

    cocos2dx 并没有setDeviceOrientation, 因为这个和具体平台有关系.  你可以通过修改PROJECT_ROOT/ios/RootViewController.mm中的 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 实现ios版本的.
      

  2.   

    //iOS:
    //RootViewController.mm里修改
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsPortrait( interfaceOrientation );
    //UIInterfaceOrientationIsPortrait竖屏
    //UIInterfaceOrientationIsLandscape横屏
    }// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
    - (NSUInteger) supportedInterfaceOrientations{
    #ifdef __IPHONE_6_0
        return UIInterfaceOrientationMaskPortrait;
    #endif
    }- (BOOL) shouldAutorotate {
        return NO;
    }
    //Android
    //在onCreate里添加
    //锁定竖屏
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
      

  3.   

    这个和平台相关,要修复对应的API
    如IOS1、新建一个cocos2d-x项目<IOS>;2、AppDelegate.cpp  中大约 84行,注释pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeRight); 
    3、重载RootViewController.mm 中的 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return UIInterfaceOrientationIsLandscape( interfaceOrientation );}4、不需要在Info.plist中添加 Supported interface orientations。