2010-10-13 63 views
1

我是iPhone編程新手,事實上,任何類型的編程。近一年來,我一直在教自己C,然後是Objective-C,在過去的幾個月中,我一直在製作一款iPhone遊戲,到目前爲止我對此感到非常自豪。從OpenGL視圖加載UIView

無論如何,我已經打了一個絆腳石,我一直試圖弄清楚一段時間,不能,如果有人能指出我正確的方向,我會非常感激。

基本上,當應用程序啓動時,它加載到UIView,這就像一個菜單系統,有「加載遊戲」,「查看高分等」選項......當「加載遊戲」被按下,一個OpenGL視圖被創建並且我的遊戲開始播放。當遊戲中的宇宙飛船撞向一顆行星時,遊戲意味着結束,另一個UIView交換顯示高分,並提示重試。我一直試圖讓這個UIView交換一段時間,但它似乎不工作。代碼全部編譯正確,沒有錯誤或警告,但是當飛船墜入行星時,什麼都不會發生。 OpenGL視圖保持爲主視圖,並且不會加載其他視圖。

這裏是我的RootViewController的類的代碼,drawEAGLView是當「加載遊戲」按下調用,當飛船墜毀NEWPAGE被稱爲:

- (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]; 

} 

我試着用搜索引擎和論壇搜索它很長一段時間,但(可能是因爲我不知道確切的使用條款),我找不到任何東西!

我儘量提供儘可能多的信息,任何幫助將非常感謝!

由於提前, 克雷格

回答

0

你確定你是在一個導航控制器?對於OpenGL遊戲似乎有點奇怪。如果替換最後一行,會發生什麼:

[self presentModalViewController:self.viewTwoController animated:YES]; 

有一對夫婦的其他東西,你正在做的,我不認爲你需要像分配glView到三個屬性。

你也只是視圖添加到窗口像你這樣做是爲了您的glView:

[window addSubview:self.viewTwoController.view]; 

,或者甚至更換觀點,

self.view = self.viewTwoController.view;