比如以下代码
CCRect rect = CCRectMake(0,0,0,0); CCRect rectInsets = CCRectMake(0,0,1,1);
CCScale9Sprite *backgroundButton = CCScale9Sprite::create("Icon.png",rect,rectInsets); CCScale9Sprite *backgroundHighlightedButton = CCScale9Sprite::create("Icon.png",rect,rectInsets); CCSize size=backgroundButton->getContentSize(); CCControlButton *m_button = CCControlButton::create(backgroundButton); m_button->setBackgroundSpriteForState(backgroundHighlightedButton, CCControlStateHighlighted); m_button->setPosition(200,200); addChild(m_button, 1);
此代码编译过去后,会出现只能点击右下角的才能按键响应,经过查找学习发现在m_button中多加这句
m_button->setPreferredSize(CCSizeMake(size.width, size.height));
及可以正常点击按键范围,不过setPreferredSize在代码提示不出来,不知道大家的版本会不会提示出来咯