TextureCache,多线程预加载纹理图,例如:
TextureCache::getInstance()->addImageAsync("board.png", addTextureCallback);//预加载纹理图
addTextureCallback是上面定义的一个回调函数,因为我是从第一张图片开始加载,每一张图片加载完成都让所定义的指针+1;
//加载完毕回调
auto addTextureCallback = [ptexture_num](Texture2D* texture)
{
(*ptexture_num)++;
log("load a texture async");
};
然后加载资源图片:
auto board = Sprite::createWithTexture(texturecache->getTextureForKey("board.png"));
board->setAnchorPoint(Vec2(0, 1));
board->setPosition(Vec2(0, visibleSize.height));
board->setOpacity(80); //满分255
addChild(board);