force update?


I am creating a new layer and a UIActivityIndicatorView right before running a long process that takes several seconds to complete. The layer and UIActivityIndicatorView don’t show up until the long process is over, even though they are being created before hand.

Is there a way to force a frame update so they will show up right away? I tried calling CCDirector::sharedDirector()->drawScene(); and that seems to make the layer draw before the long process, however the UIActivityIndicatorView does not show yet.

Thanks for any help you can give.

[SOLVED] How to force screen update in main thread?

If you’re loading lots of image files in yourLayer::init() and being blocked here, you can use CCTextureCache::addImageAsync.


In the layer init I am only loading one image that is 45kb and making a sprite out of it. I also make a text label. That’s literally all I am doing.

Here is my later func


    CCSize winSize = CCDirector::sharedDirector()->getWinSize();


    CCSprite* bg = CCSprite::spriteWithFile("activity_view_bg.png" );
    ScaleSpriteToSize( bg, 200.0f, 50.0f );
    bg->setColor( ccc3( 50, 50, 50 ) );
    bg->setPosition( ccp( winSize.width / 2.0f, winSize.height / 2.0f ) );
    this->addChild( bg, 0 );

    CCLabelTTF* pStatusBarLabel = CCLabelTTF::labelWithString( "Wait...", "Thonburi", 14 );
    pStatusBarLabel->setAnchorPoint( ccp( 0.5f, 0.5f ) );
    pStatusBarLabel->setPosition( ccp( winSize.width / 2.0f, ( winSize.height / 2.0f ) - SPINNER_STATUS_TEXT_OFFSET ) );
    this->addChild( pStatusBarLabel, 1 );


    progressBarLayer = this;

    CCPoint spinnerLocation = ccp( winSize.width / 2.0f, bg->getPosition().y - SPINNER_STATUS_TEXT_OFFSET );
    ShowUIActivityView( spinnerLocation ); // this creates a UIActivityIndicatorView

After it creates the layer I do a libCurl command that downloads some data, which takes a while. The sprite created in the layer and the UIActivityIndicatorView don’t show up though until the libCurl command is done, which is not what I wanted.


Can I ask a question about how you can crate a UIActivityIndicatorView in cocos2d-x?


Sure, I’ll see if I can remember :slight_smile: