1、修改cocos2dlibs工程下platform->ios->CCEGALview-ios.mm文件 在swapBuffer方法中添加
if ([EAGLContext currentContext] != _context) {
if (![EAGLContext setCurrentContext:_context]) {
NSLog(@"can not set current context");
}
}
2、 在.h文件中添加变量
BOOL _isBackground;
在该文件中添加方法
-(void) setIsBackground:(BOOL) flag
{
_isBackground = flag;
}
在layoutSubviews方法中判断
if(_isBackground){
return;
}
在前后台方法中添加
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
[[SDKWrapper getInstance] applicationDidEnterBackground:application];
app->applicationDidEnterBackground();
// [[TongJi getInstance]houtai];
NSLog(@"launcing......houtai1111111");
auto glview = (__bridge CCEAGLView *)cocos2d::Application::getInstance()->getView();
[glview setIsBackground:YES];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
[[SDKWrapper getInstance] applicationWillEnterForeground:application];
app->applicationWillEnterForeground();
// [[TongJi getInstance]qiantai];
NSLog(@"launcing......qiantai");
auto glview = (__bridge CCEAGLView *)cocos2d::Application::getInstance()->getView();
[glview setIsBackground:NO];
}
creator官方修改
UIApplicationState state = [[UIApplication sharedApplication] applicationState];
if (state == UIApplicationStateBackground)
https://github.com/cocos-creator/cocos2d-x-lite/pull/1918
本文由 biezhi 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为:
2020/03/02 20:54