Iphone 加载屏幕到游戏过渡

Iphone 加载屏幕到游戏过渡,iphone,ios,opengl-es,opengl-es-2.0,Iphone,Ios,Opengl Es,Opengl Es 2.0,当我启动游戏时,我希望屏幕在后台加载资源时显示加载图像。为此,我加载了一个简单的UIImageView组件,并在其中添加了一个“微调器”,以向用户反馈设备正在后台加载某些内容 当这个图像显示时,我加载我所有的图像和纹理,设置我的OpenGL视图并让它进行渲染。 当第二帧被渲染时,我想隐藏ImageView,只显示OpenGL视图。我不希望OpenGL视图显示在第一帧上,因为它需要非常长的时间来渲染 但是,在加载所有资源和设置OpenGL视图的DisplayLink以在新线程中进入渲染循环,然后在

当我启动游戏时,我希望屏幕在后台加载资源时显示加载图像。为此,我加载了一个简单的UIImageView组件,并在其中添加了一个“微调器”,以向用户反馈设备正在后台加载某些内容

当这个图像显示时,我加载我所有的图像和纹理,设置我的OpenGL视图并让它进行渲染。 当第二帧被渲染时,我想隐藏ImageView,只显示OpenGL视图。我不希望OpenGL视图显示在第一帧上,因为它需要非常长的时间来渲染

但是,在加载所有资源和设置OpenGL视图的DisplayLink以在新线程中进入渲染循环,然后在加载完成时显示OpenGL视图时,我遇到了一些问题。渲染循环似乎没有启动

以下是我的视图控制器的loadView方法

- (void)loadView 
{
CGRect mainScreenFrame = [[UIScreen mainScreen] applicationFrame];

    // Set up the image view
    UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"Startscreen" ofType:@"png"]];
    _imageView = [[UIImageView alloc] initWithFrame:mainScreenFrame];
    _imageView.image = img;

    // Set up the spinner
    _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [_spinner setCenter:CGPointMake(mainScreenFrame.size.height/3.0*1.85, mainScreenFrame.size.width/10.0*7.55)];
    [_imageView addSubview:_spinner];    
    [_spinner startAnimating];

    // Show the loading image
    self.view = _imageView;

    /* Load resources in a new thread -- this shows the spinner during loading */
    [NSThread detachNewThreadSelector:@selector(loadGLView) toTarget:self withObject:nil];
}
loadGLView只执行以下操作,初始化OpenGL视图并启动加载过程

_glView = [[JungleOpenGLView alloc] initWithFrame:mainScreenFrame];
这就是我在OpenGL视图中设置DisplayLink的方式

CADisplayLink* displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(setupRender:)];
[displayLink setFrameInterval:2];
[displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
当渲染第二帧时,我会发送一个通知,然后设置ViewController

self.view = _glView;
我发现了我的错误。 不是像这样为加载方法创建新线程:

[NSThread detachNewThreadSelector:@selector(loadGLView) toTarget:self withObject:nil];
我用过:

[self performSelectorInBackground:@selector(loadGLView) withObject:nil];
这就是诀窍。有关此主题(创建线程)的详细信息,请参见: