当我启动我的游戏时,我希望屏幕在后台加载资源时显示载入图像。我通过加载一个简单的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];
当第二个框获取呈现我发送通知和视图控制器然后将
self.view = _glView;