申请中的问题确实进入后台(issue in application did enter background)

编程入门 行业动态 更新时间:2024-10-28 19:35:00
申请中的问题确实进入后台(issue in application did enter background)

我在cocos2d-x中有一个应用程序。 我希望我的应用程序应始终运行,直到手动停止。 但是当进入后台时它会暂停,当返回时它会恢复。 我删除了代码

CCDirector::sharedDirector()->pause(); CCDirector::sharedDirector()->resume();

来自Appdelegate.cpp函数(applicationDidEnterBackground()和applicationDidEnterForeground())。 但是我的应用程序在进入后台时仍然暂停。我希望我的应用程序应该只在我接到电话或手动暂停我的应用程序时暂停,直到或除非它应该在后台运行。 请我解决这个问题。

I am having a application in cocos2d-x. I want my application should run always until manually stops. But while enters into the background it got paused and when return back it resumes. I removed the codes

CCDirector::sharedDirector()->pause(); CCDirector::sharedDirector()->resume();

from Appdelegate.cpp functions (applicationDidEnterBackground() and applicationDidEnterForeground()). But still my application got pause while enter into background.I want my application should pause only when i got a phone call or manually i pause my application, until or unless it should run in the background. Please me to solve this.

最满意答案

以下是您的应用进入后台时会发生的情况

类名>>> Cocos2dxActivity.java

@Override protected void onPause() { super.onPause(); Cocos2dxHelper.onPause(); this.mGLSurfaceView.onPause(); }

我认为代码是自我解释的,即当它进入后台时它会暂停你的应用程序(onPause的整个目的),你提到的ApplicationDelegate方法只是当活动进入后台/前景时调用的JNI函数,这样你就可以做到游戏相关的东西。 您可能知道CCDirector的暂停仅暂停运行场景(预定定时器)并将绘制速率更改为4 FPS以减少CPU消耗。

因此,在Appdelegate中删除对CCDirector的暂停/恢复调用无助于实现这些目标。 为此,您必须覆盖我上面提到的方法和相关方法,并停止活动暂停。

Here is what happens when your app goes to background

class name >>> Cocos2dxActivity.java

@Override protected void onPause() { super.onPause(); Cocos2dxHelper.onPause(); this.mGLSurfaceView.onPause(); }

I think the code is self explanatory,i.e, it is pausing your app when it enters background (the whole purpose of onPause) and the ApplicationDelegate methods you mentioned are just JNI functions called when the activity goes to background/foreground so that you can do game related stuff there. As you may know that CCDirector's pause only pauses the running scene (scheduled timers) and changes the draw rate to 4 FPS to reduce CPU consumption.

So, removing pause/resume calls to CCDirector in Appdelegate will not help achieve those goals. For that you have to override the method and related methods I mentioned above and stop the activity from pausing.

更多推荐

本文发布于:2023-07-30 06:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   确实   issue   background   enter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!