cocos2d-x CCScrollview children not affected by anchor points?

330 Views Asked by At

I am creating a CCScrollview in my app

scrollView = CCScrollView::create();
scrollView->retain();
scrollView->setViewSize(CCSize(size.width,size.height - 100));
scrollView->setContentSize(CCSize(size.width,1000));
scrollView->setDirection( kCCScrollViewDirectionVertical );
scrollView->setPosition(ccp( 0,50 ) );
scrollView->setContainer( this->getParent() );

this->addChild(scrollView, 5);

now when i add a child to the scrollview like so:

titleLabel = CCLabelTTF::create("Squares", "Thonburi", 20);
titleLabel->setPosition(ccp(0, scrollView->getViewSize().height*0.90));
scrollView->addChild(titleLabel, 1);

it renders at the correct spot which is 0,50 with an anchor point on 0,0

if i change the anchor point though to say 1,1 like so

titleLabel->setAnchorPoint(ccp(1, 1));

it still renders as if it has an anchor point of 0,0

anyone know why this happens? or how i can fix it?

1

There are 1 best solutions below

0
On

It happens, because CCScrollView resets the anchor point for added children to the container view:

void CCScrollView::addChild(CCNode * child, int zOrder, int tag)
{
    child->ignoreAnchorPointForPosition(false);
    child->setAnchorPoint(ccp(0.0f, 0.0f));
    if (m_pContainer != child) {
        m_pContainer->addChild(child, zOrder, tag);
    } else {
        CCLayer::addChild(child, zOrder, tag);
    }
}

I am actually not sure, why this is necessary. A way to fix that would be to add a CCNode to the container first and add all your children to that container.