Game Center windows don't scroll smoothly on OpenGL game
I have an shipped OpenGL game that I'm adding Game Center support to for a 1.1 rev. The game does not use a UIViewController and is coded as follows in the AppDelegate:
-(void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
glView = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
[window addSubview:glView];
[window makeKeyAndVisible];
[glView performSelectorOnMainThread:@selector(mainGameLoop) withObject:nil waitUntilDone:NO];
}
Everything works great, but when Game Center brings up a window (GKAchievementViewController for example), the w开发者_如何转开发indow animates on screen fine, but when I touch to scroll it, it doesn't have any of the momentum or bounce-back like normal windows. When I scroll the window past the top and bottom and it doesn't return with bounce back.
The window is fully functional, registers touches, it just behaves ugly.
I assume this is because some information is just not being sent down the pipe correctly because I don't have a UIViewController? I tried creating a UIViewController that sits in-between the UIWindow and the OpenGL UIView, but I get the same behavior.
This is how I'm creating the GKAchievementViewController dialog:
-(void)displayAchievements
{
achievmentsViewController = [[UIViewController alloc] init];
[glView addSubview:achievmentsViewController.view];
GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
if (achievements != nil)
{
achievements.achievementDelegate = self;
[achievmentsViewController presentModalViewController:achievements animated:YES];
}
[achievements release];
}
I don't use any of the UIKit in the game, all buttons, etc are done with straight OpenGL. I am also not using cocos2d or any other framworks.
In my main loop I am doing this:
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.002, TRUE) == kCFRunLoopRunHandledSource);
Other than that, I am not making any regular calls into the OS.
Does anyone know what is going on? My game is ready to submit other than this problem and it's driving me crazy.
OK, I think I found the answer to this so I'm going to answer my own question in the hopes of saving others a lot of frustration.
The problem is CFRunLoopRunInMode. It doesn't play nice with UIKit. I switched to using CADisplayLink and all is well.
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(mainLoopBody)];
[displayLink setFrameInterval:1];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
I've read that CADisplayLink is causing some games problems and there is a lot of debate about using it vs CFRunLoopRunInMode vs NSTimer. I'll use this for a while and see if it causes any problems, but windows scroll right again.
My one concern with CADisplayLink is if the frame rate starts to bog down. Under my old CFRunLoopRunInMode system, if the frames took longer the delta time reflected that. With CADisplayLink, I'm not sure if that is still the case.
Oh the fun of programming.
精彩评论