void CCtrlPage::SetBgAni(const char* pszAni) { if (NULL == pszAni) { return; } clearBackgroundSprite(); m_strAniSection = std::string(pszAni); if (m_strAniSection.empty()) { return; } CMyIniPtr pAni = g_objIniMgr.GetMyIniPtr(m_strAniPath.c_str()); if (!pAni) { return; } int nFrame = 0; std::string strFrame = FORMAT("Frame%d")<<nFrame; const char *pszValue = pAni->GetString(m_strAniSection.c_str(), strFrame.c_str()); if (NULL == pszValue) { return; } CCScale9Sprite *backgroundSprite = CCScale9Sprite::create(pszValue); if (!backgroundSprite) { return; }; // 不为9宫格方式 if (enumUISTRETCH_NORMAL == m_nAniStretch) { CCRect rectCapInsets = CCRectMake(0, 0, backgroundSprite->getContentSize().width, backgroundSprite->getContentSize().height); backgroundSprite->removeAllChildren(); CCScale9Sprite *backgroundSpriteResize = backgroundSprite->resizableSpriteWithCapInsets(rectCapInsets); CHECK(backgroundSpriteResize); setBackgroundSprite(backgroundSpriteResize); } else if (enumUISTRETCH_STRETCH == m_nAniStretch) { float fOrgWidth = backgroundSprite->getContentSize().width; float fOrgHeight = backgroundSprite->getContentSize().height; CCRect rectCapInsets = CCRectMake(0, 0, fOrgWidth, fOrgHeight); backgroundSprite->removeAllChildren(); CCScale9Sprite *backgroundSpriteResize = backgroundSprite->resizableSpriteWithCapInsets(rectCapInsets); CHECK(backgroundSpriteResize); float fScaleX = 1.0f; float fScaleY = 1.0f; if (0.0f != fOrgWidth && 0.0f != fOrgHeight) { fScaleX = (float)m_nWidth / fOrgWidth; fScaleY = (float)m_nHeight / fOrgHeight; } backgroundSpriteResize->setScaleX(fScaleX); backgroundSpriteResize->setScaleY(fScaleY); setBackgroundSprite(backgroundSpriteResize); } else { setBackgroundSprite(backgroundSprite); } CHECK(m_backgroundSprite); m_backgroundSprite->setAnchorPoint(ccp(0, 0)); m_backgroundSprite->setPosition(ccp(0, 0)); this->addChild(m_backgroundSprite, 0); }