我的问题涉及将 UIKit 与 Cocos2d 一起使用。
该应用程序作为 cocos2d 应用程序启动,使用 CCDirector 作为导航控制器的 rootViewController。我通过抓取 glView 的屏幕截图并立即显示该视图,然后将其动画到新视图上,从而在没有动画的情况下将另一个视图控制器推到顶部。新视图是一个包含先前场景缩略图的画廊。
[self.shelf animateOffScreen];
[UIView animateWithDuration:.2 animations:^{
self.deleteButton.center = CGPointMake(kAnimateButtonOffX, self.deleteButton.center.y);
self.infoButton.center = CGPointMake(kAnimateButtonOffX, self.infoButton.center.y);
self.galleryButton.center = CGPointMake(kAnimateButtonOffX, self.galleryButton.center.y);
self.cameraButton.center = CGPointMake(kAnimateButtonOffX, self.cameraButton.center.y);
} completion:^(BOOL finished) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
SSGalleryViewController *gallery = [storyboard instantiateViewControllerWithIdentifier:@"gallery"];
gallery.startImage = self.scene.lastScreenGrab;
gallery.playarea = self.scene;
gallery.delegate = self;
[self pushViewController:gallery animated:NO];
}];
当用户选择不同的场景开始时,已保存场景的缩略图会按比例放大以覆盖整个屏幕。
self.playarea.sceneName = feltBoard.filename;
[[NSUserDefaults standardUserDefaults] setObject:feltBoard.filename forKey:kDataArchiveKey];
[[NSUserDefaults standardUserDefaults] synchronize];
SSScene *aScene = [[SSScene alloc] initWithDelegate:self.playarea];
[aScene restoreScene];
GMGridViewCell *cell = [self getCellForKey:feltBoard.filename];
UIImageView *endView = (UIImageView*)[cell viewWithTag:kCellImageTag];
endView.center = [self.view convertPoint:endView.center fromView:cell];
[self.view addSubview:endView];
[UIView animateWithDuration:.3 animations:^{
endView.frame = CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
if (finished) {
[self.delegate dismissGallery:self];
}
}];
然后视图控制器被弹出,以便 rootViewController (CCDirector) 重新获得控制权。发生这种情况时,在显示恢复的场景之前,最后一个场景会出现瞬间闪烁。
UIView *tempView = [gallery.view viewWithTag:50];
[tempView removeFromSuperview];
[self.view insertSubview:tempView atIndex:0];
[self popViewControllerAnimated:NO];
[self.shelf animateOnScreen];
[UIView animateWithDuration:.2 animations:^{
self.deleteButton.center = CGPointMake(kAnimateButtonOnX, self.deleteButton.center.y);
self.infoButton.center = CGPointMake(kAnimateButtonOnX, self.infoButton.center.y);
self.galleryButton.center = CGPointMake(kAnimateButtonOnX, self.galleryButton.center.y);
self.cameraButton.center = CGPointMake(kAnimateButtonOnX, self.cameraButton.center.y);
} completion:^(BOOL finished) {
if (finished) {
[tempView removeFromSuperview];
}
}];
我试图通过删除节点并添加新节点来更新一个场景(这样实际上只使用了一个场景)并且我得到了闪光灯。
我尝试创建一个新场景并用它替换正在运行的场景,但我仍然看到闪光灯。
我相信我在离开现场时看到了 openGL 缓冲区中剩下的内容。但是, glFlush() 没有效果。
我认为我需要一种方法来刷新 glView 并显示当它被画廊 uiView 覆盖时我对其所做的更改。
关于可能发生的事情或我如何能够纠正这个问题的任何想法?