加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[寒江孤叶丶的Cocos2d-x之旅_22]Cocos2d-x如何不进入待机(屏幕

发布时间:2020-12-14 19:55:21 所属栏目:百科 来源:网络整理
导读:原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列] 博客地址:http://blog.csdn.net/qq446569365 方法很简单,一行代码就可以轻松搞定…… 首先是IOS的实现: 在 AppController.mm文件中的70行左右加入如下代码: [[ UIApplication

原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的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> 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读