Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested CCLayouts #887

Open
haligalaph opened this issue Jul 15, 2014 · 0 comments
Open

Nested CCLayouts #887

haligalaph opened this issue Jul 15, 2014 · 0 comments
Labels

Comments

@haligalaph
Copy link

When there are several levels of nested CCLayouts, and the lowest one needs layout, it takes several frames to update the whole hierarchy. The lowest CCLayout will be updated at the first frame, its parent will be updated next frame and so on. Cause of this there are noticeable flickers, that looks bad.
It could be overcome by adding this code into the needsLayout method:

if ([_parent isKindOfClass:[CCLayout class]])
{
    CCLayout* layout = (CCLayout*)_parent;
    [layout needsLayout];
}

But it results in layout method being called two times at one frame for all layouts in hierarchy except the lowest one. To fix this additional member variable called _layoutGuard could be added like this:

// CCLayout.m

- (void) needsLayout
{
    if(!_layoutGuard)
    {
        if ([_parent isKindOfClass:[CCLayout class]])
        {
            CCLayout* layout = (CCLayout*)_parent;
            [layout needsLayout];
        }
        _needsLayout = YES;
    }
}

- (void) layout
{
    _layoutGuard = YES;
    _needsLayout = NO;
}

- (void) layoutDone
{
    _layoutGuard = NO;
}

// CCLayoutBox.m

- (void) layout
{
    [super layout];
   ...
    [self layoutDone];
}

But this is not very good solution in my opinion. Maybe there is a better one.

@slembcke slembcke added the Bug label Jul 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants