addImageAsync这个怎么用啊?总是报错

我用TP将游戏所有的小图生成到一张大图里。
开始用这样的方法加载木有问题

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("big.plist");
CCSpriteBatchNode* node=CCSpriteBatchNode::create("big.png");
this->addChild(node);

```



由于big.png很大,加载的时候会卡屏。
所以我换成了这个
CCTextureCache::sharedTextureCache()->addImageAsync("big.png", this, callfuncO_selector(GameScene::loadingOver));

```

但是调用里面的小图片的时候就出错了Assert failed: Invalid spriteFrameName:xx.png....Assertion failed: (pFrame != __null), function createWithSpriteFrameName,


这样异步加载有什么问题吗?

我用了这个,没什么问题,我怀疑,是否你得plist文件加载有问题,或者调用小图片时,写plist映射路径有问题
或者,你在loadingover被回调之前,就去调用里面的小图片了

呵呵,我以为它回将plist同时加载进去,所以只用了这一行代码CCTextureCache::sharedTextureCache()->addImageAsync(“big.png”, this, callfuncO_selector(GameScene::loadingOver));
没有把这行也加进去
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(“big.plist”);

我觉得第一句话就已经将用到的纹理加载进去了,只不过加载的是大图片,而第二句话是告诉程序这张大图片中的信息。可以看下这篇文章。http://www.zaojiahua.com/optimization.html

可是我用这个CCTextureCache::sharedTextureCache()->addImageAsync(“big.png”, this, callfuncO_selector(GameScene::loadingOver));
总是在 callfuncO_selector那里报错说函数调用参数太多是怎么回事

bool CTestLayer::init()
{
    bool bRet=false;
    do 
    {
        CC_BREAK_IF(!CCLayer::init());

        //addImage or addImageAsync中创建纹理
        CCTextureCache::sharedTextureCache()->addImageAsync("ui_text.png",this,callfuncO_selector(CTestLayer::showSprite));

        bRet=true;
    } while (0);
    return bRet;
}

void CTestLayer::showSprite(CCObject* obj)
{
    CCTexture2D* texture_ui_text=(CCTexture2D*)obj;//传入的obj即是异步生成的纹理
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui_text.plist",texture_ui_text);//通过纹理和.plist文件加入CCSpriteFrameCache
    CCSprite* raffle_b_friend=CCSprite::createWithSpriteFrameName("raffle_b_friend.png");//尽情使用小图片吧
    raffle_b_friend->setPosition(ccp(100,100));
    this->addChild(raffle_b_friend);

    //错误,只能获取ui_text.png的纹理
    //CCTexture2D* raffle_b_diamond_texture=CCTextureCache::sharedTextureCache()->textureForKey("raffle_b_diamond.png");
    //正确,可以用这种先获取精灵帧,再从精灵帧中获取ui_text的纹理,以及大小,来构建CCSprite
    CCSpriteFrame* raffle_b_diamond_spriteframe=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("raffle_b_diamond.png");
    CCTexture2D* texture=raffle_b_diamond_spriteframe->getTexture();
    CCRect rect=raffle_b_diamond_spriteframe->getRect();
    CCSprite* raffle_b_diamond=CCSprite::createWithTexture(texture,rect); //如果纹理需要旋转,setRotation吧
    raffle_b_diamond->setRotation(false);
    raffle_b_diamond->setPosition(ccp(300,100));
    this->addChild(raffle_b_diamond);
}


```

费心了,谢谢谢谢