原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列]
博客地址:http://blog.csdn.net/qq446569365
首先是IOS的实现:
在AppController.mm文件中的70行左右加入如下代码:
[[UIApplication sharedApplication] 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>原文链接:https://www.f2er.com/cocos2dx/345243.html