每个版本都有些Bug, 这个贴希望能集中2.2.2版本中出现的简单bug及解决方法。
希望能置顶,谢谢。
楼主在开发过程中,遇到两个小问题,在这里列出来,抛砖引玉。欢迎广大高手回帖告知Bug的存在和修复方法。
1 UI编辑器里对按钮设置好尺寸,但在游戏中却没有效果。
修复方式参考:
修改UIButton.cpp,
void Button::onPressStateChangedToNormal()
{
_buttonNormalRenderer->setVisible(true);
_buttonClickedRenderer->setVisible(false);
_buttonDisableRenderer->setVisible(false);
if (_pressedTextureLoaded)
{
if (_pressedActionEnabled)
{
_buttonNormalRenderer->stopAllActions();
_buttonClickedRenderer->stopAllActions();
CCAction *zoomAction = CCScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
_buttonNormalRenderer->runAction(zoomAction);
_buttonClickedRenderer->setScale(_pressedTextureScaleXInSize, _pressedTextureScaleYInSize);
}
}
else if (_pressedActionEnabled) // 添加
{
_buttonNormalRenderer->stopAllActions();
CCAction *zoomAction = CCScaleTo::create(0.05f, _normalTextureScaleXInSize, _normalTextureScaleYInSize);
_buttonNormalRenderer->runAction(zoomAction);
}
}
2 UI编辑器里设置好字体颜色,但在游戏中却没有效果。
修改UITextField.h,新增TextField类成员函数
virtual void setColor(const ccColor3B &color);
修改UITextField.cpp,新增
void TextField::setColor(const ccColor3B &color)
{
Widget::setColor(color);
_textFieldRenderer->setColor(color);
}
3 文本控件Label,无法设置空字符串,如Label::setText("")
修改 UILabel.cpp
void Label::setText(const std::string& text)
{
// if (text.size()==0) // 注释掉这两行,
// return;
_labelRenderer->setString(text.c_str());
labelScaleChangedWithSize();
}
看到论坛牛人贴,在这里转来收藏一下,以便查阅
往期回顾:
【 每日·槽】第1话 – 论setEnabled和setVisible http://www.cocoachina.com/bbs/read.php?tid=181496
【 每日·槽】第2话 – 模态窗口的制作 http://www.cocoachina.com/bbs/read.php?tid=181959
【 每日·槽】第3话 --TextField的七宗罪 http://www.cocoachina.com/bbs/read.php?tid=182207
【 每日·槽】第4话 – UITextField 中文字符的长度检测问题 http://www.cocoachina.com/bbs/read.php?tid=187118
