void Layout::setBackGroundImage(const std::string& fileName,TextureResType texType) { if (fileName.empty()) { return; } if (_backGroundImage == nullptr) { addBackGroundImage(); _backGroundImage->setScale9Enabled(_backGroundScale9Enabled); } _backGroundImageFileName = fileName; _bgImageTexType = texType; switch (_bgImageTexType) { case TextureResType::LOCAL: _backGroundImage->initWithFile(fileName); break; case TextureResType::PLIST: _backGroundImage->initWithSpriteFrameName(fileName); break; default: break; } if (_backGroundScale9Enabled) { _backGroundImage->setPreferredSize(_contentSize); } _backGroundImageTextureSize = _backGroundImage->getContentSize(); _backGroundImage->setPosition(_contentSize.width/2.0f, _contentSize.height/2.0f); updateBackGroundImageRGBA(); }
void Layout::setBackGroundImage(const char* fileName,TextureResType texType) { if (!fileName || strcmp(fileName, "") == 0) { return; } if (_backGroundImage == NULL) { addBackGroundImage(); } _backGroundImageFileName = fileName; _bgImageTexType = texType; if (_backGroundScale9Enabled) { extension::CCScale9Sprite* bgiScale9 = static_cast<extension::CCScale9Sprite*>(_backGroundImage); switch (_bgImageTexType) { case UI_TEX_TYPE_LOCAL: bgiScale9->initWithFile(fileName); break; case UI_TEX_TYPE_PLIST: bgiScale9->initWithSpriteFrameName(fileName); break; default: break; } bgiScale9->setPreferredSize(_size); } else { switch (_bgImageTexType) { case UI_TEX_TYPE_LOCAL: static_cast<CCSprite*>(_backGroundImage)->initWithFile(fileName); break; case UI_TEX_TYPE_PLIST: static_cast<CCSprite*>(_backGroundImage)->initWithSpriteFrameName(fileName); break; default: break; } } _backGroundImageTextureSize = _backGroundImage->getContentSize(); _backGroundImage->setPosition(CCPoint(_size.width/2.0f, _size.height/2.0f)); updateBackGroundImageRGBA(); }