2012-04-20 20 views
4

ゲームを再起動すると、メモリー不足の警告でクラッシュします。 私はEAGLViewを閉じてすべてのプロセスを停止する方法を探しています。 私はあなたに何を見せるか分からないので、必要に応じてもっと情報を求めてください。EAGLViewを終了してすべてのプロセスを停止する

私は、mainGameLoopが続くEAGLViewを持っています。

- (void)mainGameLoop { 

    // Create variables to hold the current time and calculated delta 
    CFTimeInterval  time; 
    float    delta; 

    // This is the heart of the game loop and will keep on looping until it is told otherwise 
    while(true) { 

     // Create an autorelease pool which can be used within this tight loop. This is a memory 
     // leak when using NSString stringWithFormat in the renderScene method. Adding a specific 
     // autorelease pool stops the memory leak 
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

     // I found this trick on iDevGames.com. The command below pumps events which take place 
     // such as screen touches etc so they are handled and then runs our code. This means 
     // that we are always in sync with VBL rather than an NSTimer and VBL being out of sync 
     while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.02, TRUE) == kCFRunLoopRunHandledSource); 

     // Get the current time and calculate the delta between the lasttime and now 
     // We multiply the delta by 1000 to give us milliseconds 
     time = CFAbsoluteTimeGetCurrent(); 
     delta = (time - lastTime) * 1000; 

     // Go and update the game logic and then render the scene 
     [self updateScene:delta]; 
     [self renderScene]; 

     // Set the lasttime to the current time ready for the next pass 
     lastTime = time; 

     // Release the autorelease pool so that it is drained 
     [pool release]; 
    } 
} 
+0

まず、ゲームループから脱出する方法が必要です。 'while()'条件を実際に値と照合させることについて考えましたか?また、 'while()'ループを使うと、ディスプレイを更新する最良の方法ではないかもしれません。実際には、CADisplayLinkを使って調べるべきです。最後に、[EAGLViewは株式のCocoaクラスではありません](http://stackoverflow.com/a/8438138/19679)、それはAppleのサンプルコードで時々使用されるOpenGL ES CAEAGLLayerをホストするカスタムUIViewであるため、それが何であるかを知らないかもしれない。 –

+0

この例はraw mainGameLoopです。私は誰かがそれをやるもう一つの方法を持っているかもしれないと思った。 Atm私はwhile(self.hidden == FALSE)を使用していて、スコアなどを表示するときに表示を隠しています。 私のゲームは中断します(CFRunLoopRunInMode(kCFRunLoopDefaultMode、0.02、TRUE)== kCFRunLoopRunHandledSource);ゲームを数回再生した後、今すぐ。 – Lohardt

+1

代わりにNSTimerやCADisplayLinkを使用してみませんか? – Max

答えて

0

私はゲームを公開しました。私はEAGLViewを使用しました。私は自分のフレーム/秒を制御するためにタイマーを使用しました(また、デバイス自体の電力使用率を制御する良い方法とも言えます)。

ゲームを終了するとき(ホームボタンを押しても)すべてのインスタンスを認識して、退出ルーチンのすべてのビットを制御するのが最善の方法です。上記のタイマーを実装する場合は、タイマーを停止したり、アイテムを無効にしたりすることができます。

再入荷時には、APIを実装することで本質的にあなたの存在を知る機会が与えられますゲーム内の状態からあなたのアプリが最初から完全に再起動されてから再入力されました。

関連する問題