[寒江孤葉丶的Cocos2d-x之旅_22]Cocos2d-x如何不進入待機(螢幕保持喚醒 不鎖屏 不變黑……)
阿新 • • 發佈:2019-02-13
原創文章,歡迎轉載,轉載請註明:文章來自[寒江孤葉丶的Cocos2d-x之旅系列]
部落格地址:http://blog.csdn.net/qq446569365
方法很簡單,一行程式碼就可以輕鬆搞定……
首先是IOS的實現:
在AppController.mm檔案中的70行左右加入如下程式碼:
[[UIApplicationsharedApplication] setIdleTimerDisabled:YES];
程式碼如下:// Set RootViewController to window if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) { // warning: addSubView doesn't work on iOS6 [window addSubview: _viewController.view]; } else { // use this method on ios6 [window setRootViewController:_viewController]; } [window makeKeyAndVisible]; //阻止IOS系統進入休眠 [[UIApplication sharedApplication] setIdleTimerDisabled:YES];//就是這行! //隱藏狀態列 [[UIApplication sharedApplication] setStatusBarHidden:true]; // IMPORTANT: Setting the GLView should be done after creating the RootViewController cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView); cocos2d::Director::getInstance()->setOpenGLView(glview); cocos2d::Application::getInstance()->run();
Android實現:
安卓實現也非常簡單的就是修改在AndroidManifest.xml檔案裡面用user-permission宣告:
加入如下程式碼:
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<supports-screens android:anyDensity="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WAKE_LOCK"/><!--這行就是--> </manifest>