cocos2d-x 菜单按钮点击居中放大
cocos2d-x 创建菜单按钮的时候可以设置普通和选中状态两种图片,如下:
CCMenuItemImage* itemQuickGame = CCMenuItemImage::create("btn_quick_game.png","btn_quick_game_pre.png", this, menu_selector(TOMainMenuScene::callbackMenus));
如果第二张图片比第一张大就可以做到点击放大效果,但是默认是按照左下角放大的,我们需要以中心点放大,所以修改下底层代码: www.zzzyk.com
bool CCMenuItemSprite::initWithNormalSprite(CCNode* normalSprite,CCNode* selectedSprite, CCNode* disabledSprite,CCObject* target, SEL_MenuHandler selector)
{
CCMenuItem::initWithTarget(target, selector);
setNormalImage(normalSprite);
setSelectedImage(selectedSprite);
setDisabledImage(disabledSprite);
//设置按钮从中心点放大
if (selectedSprite && normalSprite) {
selectedSprite->setPosition(
(normalSprite->getContentSize().width-selectedSprite->getContentSize().width)/2.0f,
(normalSprite->getContentSize().height-selectedSprite->getContentSize().height)/2.0f);
}
//end
if(m_pNormalImage)
{
this->setContentSize(m_pNormalImage->getContentSize());
}
return true;
}
补充:移动开发 , 其他 ,