4

ゲームを再起動すると、メモリ不足の警告が表示されてクラッシュします。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];
    }
}
4

1 に答える 1

0

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

最善の方法は、ゲームを終了する (ホーム ボタンを押しても) すべてのインスタンスを認識し、終了ルーチンのすべてを制御することです。上記のタイマーを実装すると、タイマーを停止したり、ロックを解除したりできます...

再エントリ時に、API でルーチンが提供されます。これを実装すると、基本的に、ゲーム内の状態から再エントリするのではなく、アプリを最初から完全に再起動することを知る機会が得られます。

于 2012-05-24T16:30:31.380 に答える