cocos2d-x CCScale9Sprite執行個體

來源:互聯網
上載者:User
    // 只是簡單擷取一形大小         CCSprite* tmp = CCSprite::create("extensions/background.png");        CCSize size = tmp->getContentSize();        CCRect fullRect = CCRectMake(0,0, size.width, size.height);        CCRect insetRect = CCRectMake(3,3,size.width-6, size.height-6);        CCLog("wh:%f,%f", size.width, size.height);        tmp->release(); // 調用CCScale9Sprite        CCScale9Sprite* backGround = CCScale9Sprite::create("extensions/background.png", fullRect, insetRect );         backGround->setPreferredSize(CCSizeMake(300, 30));        backGround->setPosition(ccp(10, 230));        backGround->setAnchorPoint(CCPointZero);        addChild(backGround);

加入圖片是圓角圖片,圓角半徑為3,圖片大小為16x16,則rectInsets最好設定為(3,3,10,10); 其中,3,3是中間地區的起點,10,10是中間地區的寬高,10是16-2*3的結果.

注意:在測試中發現,如果想要setPreferredSize()或者setContentSize()在收縮圖片時生效,則只能用

 CCScale9Sprite::create("extensions/background.png", fullRect, insetRect ) 這個建構函式,用
 CCScale9Sprite::create("extensions/background.png") 或者
CCScale9Sprite::create(insetRect,"extensions/background.png", )
這兩個create函數構造出來的CCScale9Sprite都無法按照理想中的收縮,但展開是沒問題的!

BUG原因:

CCScale9Sprite* CCScale9Sprite::create(CCRect capInsets, const char* file)的實現有誤,應該將該函數中的

if ( pReturn && pReturn->initWithFile(file,capInsets) )
{
pReturn->autorelease();
return pReturn;
}

改為

if ( pReturn && pReturn->initWithFile(capInsets, file) )
{
pReturn->autorelease();
return pReturn;
}

即可



 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.