Issue when loading CCControlButton from ccbi


#1

Hi there,

I’m just taking a look at the new CocosBuilder loading stuff, and generally it’s pretty awesome. However, I’ve found a small problem: when loading a ccbi with a CCControlButton inside it, Cocos2d-x crashes with an “Unexpected property: backgroundSpriteFrame|4” error. This can be mitigated by loading up the ccb before publishing and changing the “backgroundSpriteFrame|4” and “titleColor|4” properties from 4 to 3, but the CocosBuilder app seems intend on saving them non-sequentially all the time. It’s kind of annoying having to change all the properties manually every time you want to republish. :slight_smile:

Does anybody know why CocosBuilder is so keen to leave out number 3 in it’s sprite frame list? And shouldn’t Cocos2d-x cope with this weirdness regardless?

Thanks for your help.

Ben


#2

What’s the version of CocosBuilder you use? Maybe you should try a version on github(https://github.com/cocos2d/CocosBuilder).
Just let me know whether it works? :slight_smile:


#3

Hi James,

Yep that was my first thought too, but unfortunately this behaviour still takes place when I compile the latest version from Github.

Thanks for your help,

Ben


#4

I get same problem.


#5

It seems to be a bug in cocos-2dx. If you look at CCControl.h (from CocosBuilder), you have the following block inside:

/** The possible state for a control.  */
enum 
{
    CCControlStateNormal       = 1 << 0, // The normal, or default state of a control—that is, enabled but neither selected nor highlighted.
    CCControlStateHighlighted  = 1 << 1, // Highlighted state of a control. A control enters this state when a touch down, drag inside or drag enter is performed. You can retrieve and set this value through the highlighted property.
    CCControlStateDisabled     = 1 << 2, // Disabled state of a control. This state indicates that the control is currently disabled. You can retrieve and set this value through the enabled property.
    CCControlStateSelected     = 1 << 3  // Selected state of a control. This state indicates that the control is currently selected. You can retrieve and set this value through the selected property.
};

And when you have a look at CCControlButtonLoader.cpp in cocos2d-x, you have this:

#define PROPERTY_ZOOMONTOUCHDOWN "zoomOnTouchDown"
#define PROPERTY_TITLE_NORMAL "title|1"
#define PROPERTY_TITLE_HIGHLIGHTED "title|2"
#define PROPERTY_TITLE_DISABLED "title|3"
#define PROPERTY_TITLECOLOR_NORMAL "titleColor|1"
#define PROPERTY_TITLECOLOR_HIGHLIGHTED "titleColor|2"
#define PROPERTY_TITLECOLOR_DISABLED "titleColor|3"
#define PROPERTY_TITLETTF_NORMAL "titleTTF|1"
#define PROPERTY_TITLETTF_HIGHLIGHTED "titleTTF|2"
#define PROPERTY_TITLETTF_DISABLED "titleTTF|3"
#define PROPERTY_TITLETTFSIZE_NORMAL "titleTTFSize|1"
#define PROPERTY_TITLETTFSIZE_HIGHLIGHTED "titleTTFSize|2"
#define PROPERTY_TITLETTFSIZE_DISABLED "titleTTFSize|3"
#define PROPERTY_LABELANCHORPOINT "labelAnchorPoint"
#define PROPERTY_PREFEREDSIZE "preferedSize" // TODO Should be "preferredSize". This is a typo in cocos2d-iphone, cocos2d-x and CocosBuilder!
#define PROPERTY_BACKGROUNDSPRITEFRAME_NORMAL "backgroundSpriteFrame|1"
#define PROPERTY_BACKGROUNDSPRITEFRAME_HIGHLIGHTED "backgroundSpriteFrame|2"
#define PROPERTY_BACKGROUNDSPRITEFRAME_DISABLED "backgroundSpriteFrame|3"

1 << 2 equals 4, not 3, here is where the bug is lying

TsuG.


#6

Well spotted Bertrand. Changing the values in CCControlButtonLoader.cpp fixes the problem. Thanks very much for your help.

Ben


#7

Hi guys, thanks for your job. I committed https://github.com/cocos2d/cocos2d-x/pull/1139 for this bug.
So the problem is that:
# The current test suite didn’t cover DISABLED state of CCControlButton
# CocosBuilder v2.0 always generate “4” for CCControlButton::DISABLED state, while the ccb & ccbi file in test suite is manually modified to “3”

Issue #1409 created.