天天看點

異步加載圖檔提高速度

在Cocos線程中

  • 1.加載圖檔 
Director::getInstance()->getTextureCache()->addImageAsync(
    "xxx.png", CC_CALLBACK_1(LoadingpngCallBack, this));
           
  • 2.回調函數
sem_t semTest;
void LoadingpngCallBack(cocos2d::Texture2D *texture)
{
    Texture2D *test = Director::getInstance()->getTextureCache()->getTextureForKey("xxx.png");
    if (test)
    {
        SpriteFrameCache::getInstance()->addSpriteFramesWithFile("xxx.plist", test);
    }
    sem_post(&semTest);
}
           

在另外的線程中

sem_wait(&semText);
           

信号量等待,圖檔加載完成。。。

繼續閱讀