TextureCache* cache = TextureCache::getInstance();
Size size = panel->getContentSize();
//获得基本容器八分之一的宽度
float panelHalfWidth = size.width /8;
//五分之一高度
float panelHalfHeight = size.height /5;
//原点与每个节点的中心的偏移
float offsetWidth = panelHalfWidth / 2;
float offsetHeight = panelHalfHeight /2;
for (size_t i = 0; i < index; i++)
{
//加载csb
Node* item = CSLoader::createNode("SignInElement.csb");
//获取图片精灵
Sprite* sp = item->getChildByName<Sprite*>("Sprite_1");
//更改精灵图片名称
std::string name = StringUtils::format("icon/item1_0%d%d.png",(i+1)/10,(i+1)%10);
//获取图片
Texture2D* tex = cache->addImage(name);
//设置图片
sp->setTexture(tex);
item->setPosition(panelHalfWidth*(i%8) + offsetWidth, size.height-(panelHalfHeight*(i/8) + offsetHeight));
panel->addChild(item);
}
//需要注意的是图片名称需要连续的,而且需要的图片每个都要发布