block实现场景切换
2013-02-21 16:50
435 查看
1 loadingLayer=[LoadingLayernode];
2
3 谛力泰克网:app定制http://www.dilitech.com
4 [self addChild:loadingLayer];
5 dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
6 dispatch_async(queue, ^{
7 //声明一个Pool来自动管理指针
8 NSAutoreleasePool *autoreleasepool =[[NSAutoreleasePool alloc] init];
9
10 //加锁保护,并保证与Cocos2d本身的异步加载函数本身不冲突
11 //也就是保护ShareGroup不被同时修改
12 //
[[CCTextureCachesharedTextureCache].contextLock lock];
13
14 //auxGLcontext必须是static
15 //
16 if( auxGLcontext == nil ) {
17 //新建一个EAGLContext然后与已经生成与使用的OpenGL公用一个ShareGroup
18 auxGLcontext = [[EAGLContextalloc]initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[[[[CCDirectorsharedDirector] openGLView] context]
sharegroup]];
19
20 //检查是否
21 if( ! auxGLcontext )CCLOG(@"cocos2d: TextureCache: Could not create EAGL context");
22 }
23
24 CCScene *scene;
25
26 //设置Context,拥有修改权利,接下来我们就可以正常的使用我们生成我们自己的Scene了
27 if( [EAGLContextsetCurrentContext:auxGLcontext] ) {
28 //初始化
29 scene = [LevelController scene];
30 [[CCDirector sharedDirector]replaceScene:scene];
31 }
32
33 //回到主线程,保留并解锁,然后等等主线程接收方响应并开始切换场景
34 dispatch_async(dispatch_get_main_queue(),^{
35 //防止指针丢失
36 //
nextScene = [scene retain];
37 //lock用来判断scene是否生存完
38 //
lock = NO;
39 });
40
41 //恢复
42 [EAGLContext setCurrentContext:nil];
43 //
[[CCTextureCachesharedTextureCache].contextLock unlock];
44 [autoreleasepool release];
45 });
复制代码
如果用下列常规方式回出现场景图片与动画均显示不了的问题
46 loadingLayer=[LoadingLayernode];
47 [self addChild:loadingLayer];
48 dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
49 dispatch_async(queue, ^{
50 CCScene *levelScene = [LevelControllerscene];
51 [[CCDirector sharedDirector]replaceScene:levelScene];
52 dispatch_async(dispatch_get_main_queue(),^{
53 [loadingLayer removeFromParentAndCleanup:YES];
54 });
55 });
复制代码
文章出处:谛力泰克网 app开发 http://www.dilitech.com
2
3 谛力泰克网:app定制http://www.dilitech.com
4 [self addChild:loadingLayer];
5 dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
6 dispatch_async(queue, ^{
7 //声明一个Pool来自动管理指针
8 NSAutoreleasePool *autoreleasepool =[[NSAutoreleasePool alloc] init];
9
10 //加锁保护,并保证与Cocos2d本身的异步加载函数本身不冲突
11 //也就是保护ShareGroup不被同时修改
12 //
[[CCTextureCachesharedTextureCache].contextLock lock];
13
14 //auxGLcontext必须是static
15 //
16 if( auxGLcontext == nil ) {
17 //新建一个EAGLContext然后与已经生成与使用的OpenGL公用一个ShareGroup
18 auxGLcontext = [[EAGLContextalloc]initWithAPI:kEAGLRenderingAPIOpenGLES1 sharegroup:[[[[CCDirectorsharedDirector] openGLView] context]
sharegroup]];
19
20 //检查是否
21 if( ! auxGLcontext )CCLOG(@"cocos2d: TextureCache: Could not create EAGL context");
22 }
23
24 CCScene *scene;
25
26 //设置Context,拥有修改权利,接下来我们就可以正常的使用我们生成我们自己的Scene了
27 if( [EAGLContextsetCurrentContext:auxGLcontext] ) {
28 //初始化
29 scene = [LevelController scene];
30 [[CCDirector sharedDirector]replaceScene:scene];
31 }
32
33 //回到主线程,保留并解锁,然后等等主线程接收方响应并开始切换场景
34 dispatch_async(dispatch_get_main_queue(),^{
35 //防止指针丢失
36 //
nextScene = [scene retain];
37 //lock用来判断scene是否生存完
38 //
lock = NO;
39 });
40
41 //恢复
42 [EAGLContext setCurrentContext:nil];
43 //
[[CCTextureCachesharedTextureCache].contextLock unlock];
44 [autoreleasepool release];
45 });
复制代码
如果用下列常规方式回出现场景图片与动画均显示不了的问题
46 loadingLayer=[LoadingLayernode];
47 [self addChild:loadingLayer];
48 dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
49 dispatch_async(queue, ^{
50 CCScene *levelScene = [LevelControllerscene];
51 [[CCDirector sharedDirector]replaceScene:levelScene];
52 dispatch_async(dispatch_get_main_queue(),^{
53 [loadingLayer removeFromParentAndCleanup:YES];
54 });
55 });
复制代码
文章出处:谛力泰克网 app开发 http://www.dilitech.com
相关文章推荐
- 【iphone游戏开发】Iphone游戏开发之五:游戏场景切换,点阵字的实现和Hiero工具的利用
- Cocos2d-x学习(十一):用cocos2d-x实现MoonWarriors(游戏场景切换和主菜单实现)
- Unity实现场景切换的方法
- Android共享元素场景切换动画的实现
- Cocos2d-x学习(十一):用cocos2d-x实现MoonWarriors(游戏场景切换和主菜单实现)
- VUE+WebPack前端游戏设计:依赖VUE组件通讯机制实现场景游戏切换
- Kbengine+Unity实现简单的注册登录 登陆成功切换场景
- cocos场景切换时的loading界面实现
- 3.cocos2dx它Menu,由menu为了实现场景切换
- 用application实现场景的切换
- Unity实现场景切换的方法
- 实现场景的切换
- Unity 利用协同程序实现场景切换时加载进度的监控
- Android共享元素场景切换动画的实现
- cocos2d-x实现场景切换效果
- 【iphone游戏开发】Iphone游戏开发之五:游戏场景切换,点阵字的实现和Hiero工具的利用
- Unity 利用协同程序实现场景切换时加载进度的监控
- 3.cocos2dx之Menu,通过menu来实现场景的切换
- (转)Android游戏开发之切换游戏场景特效的实现 (十九)
- unity中实现异步切换场景