开发者

Help with flickering when reloading an openGL scene

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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜