cocos2d 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函数, 否则会导致显示不正确.
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函数, 否则会导致显示不正确.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询