帮助解决重新加载 openGL 场景时的闪烁问题
我开始为问了这么多问题却无法回答任何人的问题而感到难过,但一旦我找到一些我能回答的问题,我就会的!坦白说......
Besically,我有一个gameLoop,它运行我正在制作的游戏中的所有内容,并且菜单中和游戏中的一切都运行良好,但是当我退出游戏然后重新加载菜单屏幕时屏幕闪烁。
这是我的游戏循环,希望它能提供一些见解。
//A game loop that is triggered by a timer with intervals of 1/60 seconds
- (void)gameLoop
{
// we use our own autorelease pool so that we can control when garbage gets collected
NSAutoreleasePool * apool = [[NSAutoreleasePool alloc] init];
thisFrameStartTime = [levelStartDate timeIntervalSinceNow];
deltaTime = lastFrameStartTime - thisFrameStartTime;
lastFrameStartTime = thisFrameStartTime;
// add any queued scene objects
if ([objectsToAdd count] > 0)
{
[sceneObjects addObjectsFromArray:objectsToAdd];
[objectsToAdd removeAllObjects];
}
// update our model
[self updateModel];
// send our objects to the renderer
[self renderScene];
// remove any objects that need removal
if ([objectsToRemove count] > 0)
{
[sceneObjects removeObjectsInArray:objectsToRemove];
[objectsToRemove removeAllObjects];
}
[apool release];
if (needToLoadScene)
{
[sceneObjects removeAllObjects];
[self loadScene];
}
if (needToEndScene)
{
[sceneObjects removeAllObjects];
[self stopAnimation];
//We'll need to add unloading sounds later on
[inputController endScene];
[self renderScene];
needToEndScene = NO;
}
}
我唯一应该添加的另一件事是该视图由类 MusicAndViewController
控制,我将其用作视图,然后向其中添加后续视图。菜单和游戏视图实际上是相同的 openGL 视图,但我在切换到其他视图之前渲染了一个干净的视图
I'm starting to feel bad for asking so many questions and not being able to answer anyone's, but as soon as I find some that I can, I will! Confession out of the way...
Besically I have a gameLoop that runs everything in a game that I'm making and everything works fine in the menu and then in the game, but when I quit the game and then reload the menu screen the screen flickers.
Here is my game loop, I hope it provides some insight.
//A game loop that is triggered by a timer with intervals of 1/60 seconds
- (void)gameLoop
{
// we use our own autorelease pool so that we can control when garbage gets collected
NSAutoreleasePool * apool = [[NSAutoreleasePool alloc] init];
thisFrameStartTime = [levelStartDate timeIntervalSinceNow];
deltaTime = lastFrameStartTime - thisFrameStartTime;
lastFrameStartTime = thisFrameStartTime;
// add any queued scene objects
if ([objectsToAdd count] > 0)
{
[sceneObjects addObjectsFromArray:objectsToAdd];
[objectsToAdd removeAllObjects];
}
// update our model
[self updateModel];
// send our objects to the renderer
[self renderScene];
// remove any objects that need removal
if ([objectsToRemove count] > 0)
{
[sceneObjects removeObjectsInArray:objectsToRemove];
[objectsToRemove removeAllObjects];
}
[apool release];
if (needToLoadScene)
{
[sceneObjects removeAllObjects];
[self loadScene];
}
if (needToEndScene)
{
[sceneObjects removeAllObjects];
[self stopAnimation];
//We'll need to add unloading sounds later on
[inputController endScene];
[self renderScene];
needToEndScene = NO;
}
}
The only other thing that I should add is that the view is controlled by a class MusicAndViewController
which I use as a view and then add subsequent views to. The menu and game views are actually the same openGL view but I render a clean view before switching to the other view
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何与我遇到类似问题的人都为我解决了这个问题。
设置计时器时,我必须覆盖设置器,使其失效,然后设置计时器。在我的 gameScene 上,我没有这样做,所以当我使计时器 = nil 时,它会继续触发(因为在将其设置为 nil 之前它没有失效,并且仍在运行),然后导致下一个加载的场景闪烁(菜单)
Anyone who has a similar problem to what I have had what solved it for me is this.
When setting a timer I had to override the setter so that it invalidated and then set the timer. On my gameScene I hadn't done this so when I make the timer = nil it continues to fire (as it hadn't been invalidated before setting it to nil, and was still running) and then cause a flickering on the next loaded scene (the menu)