PDA

View Full Version : Loading a UIView from an OpenGL View.




graig99
Oct 10, 2010, 04:43 PM
Hi guys

I'm new to iPhone programming, and in fact, programming of any kind. For nearly a year now I've been teaching myself C, and then Objective-C, and for the past few months I've been making an iPhone game, so far of which i'm pretty proud of.

Anyways I've hit quite a stumbling block and I've been trying to figure it out for a while now, and can't, and I would really appreciate it if someone could point me in the right direction.

Basically when the app is launched, it loads into a UIView, which is kind of like a menu system, with the options to "load game", "view highscores" etc...when "load game" is pressed, an OpenGL view is created and my game begins playing. When the spaceship in the game crashes into a planet, the game is MEANT to end, and another UIView swapped in to show highscores and present the option to retry. I have been trying to get this UIView to swap in for a while now, but it just doesn't seem to work. The code all compiles correctly with no errors or warnings, but when the spaceship crashes into the planet, nothing happens. The OpenGL view stays as the primary view, and no other view is ever loaded.

Here is the code for my RootViewController class, drawEAGLView is called when "load game" is pressed, and newPage is called when the spaceship crashes:


- (IBAction)drawEAGLView:(id)sender { //This code is called when "Load Game" is pressed in the first UIView.

//This function contains the loading code of the OpenGl view, and seems to work well.

BBSceneController * sceneController = [BBSceneController sharedSceneController];

// make a new input view controller, and save it as an instance variable
BBInputViewController * anInputController = [[BBInputViewController alloc] initWithNibName:nil bundle:nil];
sceneController.inputController = anInputController;
[anInputController release];
// init our main EAGLView with the same bounds as the window
EAGLView * glView = [[EAGLView alloc] initWithFrame:window.bounds];
sceneController.inputController.view = glView;
sceneController.openGLView = glView;
self.view = glView;
[glView release];

glView.alpha = 0.0;

[UIView beginAnimations:@"fadeout" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
// Change any animatable properties here
glView.alpha = 1.0;
[UIView commitAnimations];


// set our view as the first window view
[window addSubview:sceneController.inputController.view];
[window makeKeyAndVisible];



// begin the game.
[sceneController loadScene];
[sceneController startScene];


}



- (void)newPage //This code is run when the spaceship crashes into the planet.
{

NSLog(@"ViewTwoLoaded"); //This is logged in the console, which proves the code is being run.

if(self.viewTwoController == nil)
{
ViewTwoController *viewTwo = [[ViewTwoController alloc]
initWithNibName:@"View2" bundle:[NSBundle mainBundle]]; //View2 is the nib i want to load, but does not load.
self.viewTwoController = viewTwo;
[viewTwo release];
}

[self.navigationController pushViewController:self.viewTwoController animated:YES];

}


I've tried googling and searching in forums for it for ages, but (possibly because I don't know the exact right terms to use), i cant find anything!

I have tried to provide as much information as possible, and any help would be most greatly appreciated!

Thanks in advance,
Craig