2012-04-20 4 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), OpenGL ES CAEAGLLayer를 호스트하는 사용자 정의 UIView 일 뿐이므로 때때로 Apple의 샘플 코드에서 사용되므로 일부 사람들 그것이 무엇인지 모를 수도 있습니다. –

+0

예제는 원시 mainGameLoop입니다. 나는 누군가 다른 방법으로 그것을 할 수 있다고 생각했다. Atm 나는 while (self.hidden == FALSE)을 사용하고 점수 등을 표시 할 때보기를 숨 깁니다. 내 게임이 중단됩니다 (CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.02, TRUE) == kCFRunLoopRunHandledSource); 지금 게임을 몇 번 재생 한 후 – Lohardt

+1

대신 NSTimer 또는 CADisplayLink를 사용하지 않는 이유는 무엇입니까? – Max

답변

0

나는 게임을 발표했으며, 나는 EAGLView를 사용했다. 또한 타이머를 사용하여 Frames/Second (장치 자체의 전력 사용량을 제어하는 ​​좋은 방법이라고도 함)를 제어합니다.

게임을 종료 할 때 (홈 버튼을 눌렀을 때조차도) 모든 인스턴스를 인식하고 종료 루틴의 모든 비트를 제어하는 ​​것이 가장 좋습니다. 위의 타이머를 구현하면 타이머 등을 중지 할 수 있습니다.

다시 입력 할 때 API를 구현하면 기본적으로 구현하면 게임 상태에서 재 입력 한 대 앱이 처음부터 완전히 재개되었습니다.