gpt4 book ai didi

ios - 关闭 EAGLView 并停止所有进程

转载 作者:可可西里 更新时间:2023-11-01 06:16:46 24 4
gpt4 key购买 nike

重新启动我的游戏时,它崩溃并显示内存不足警告。我正在寻找一种关闭 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];
}
}

最佳答案

我发布了一个游戏,我使用了 EAGLView。我还使用了一个计时器来控制我的帧数/秒(据说这也是控制设备本身电源利用率的好方法)。

最好的方法是在退出游戏(甚至按下主页按钮)时识别所有实例并控制退出例程的每一点。如果实现上面的定时器,你可以停止定时器,释放东西等等......

重新进入时,您会在 API 中获得例程,如果您实现这些例程,您将有机会知道您是从游戏中状态重新进入还是您的应用程序是从头开始完全重新启动。

关于ios - 关闭 EAGLView 并停止所有进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10245957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com