cocos2d-x CCControlButton用法

    CCScale9Sprite *backgroundButton = CCScale9Sprite::create(btnImg, imgRect, imgRectInsets);
    CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create(hightLightBtnImg, imgRect, imgRectInsets);
    m_button = CCControlButton::create(backgroundButton);
    m_button->setZoomOnTouchDown(false); //设置不现实按钮效果
    m_button->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted);
    m_button->setPreferredSize(CCSizeMake(size.height, size.height));
    //m_button->setContentSize(CCSizeMake(size.height, size.height));
    m_button->setPosition(m_label->getContentSize().width + m_button->getContentSize().width/2, m_button->getContentSize().height/2);
    addChild(m_button, 1);

需要注意的是注释的

m_button->setContentSize(CCSizeMake(size.height, size.height));

这句,调整CCControlButton的大小不能用setContentSize, 只能setPreferredSize函数, 否则会导致显示不正确.

原文链接: https://www.cnblogs.com/moodlxs/archive/2012/12/26/2834246.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    cocos2d-x CCControlButton用法

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/390587

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月30日 下午3:50
下一篇 2023年3月30日 下午3:50

相关推荐