CCMenuItemToggle can't follow CCArray?

CCMenuItemToggle can't follow CCArray?
0.0 0


Hi there

It is my code

CCMenuItemToggle item3 = CCMenuItemToggle::createWithTarget, CCMenuItemFont::create, CCMenuItemFont::create);
But, I want to use CCArray.
Because, original “cocos2d for iPhone” code use NSArray.
toggleMenuItems = [NSArray arrayWithObjects:[CCMenuItemFont itemWithString:"ON"] ,[NSArray arrayWithObjects:[CCMenuItemFont itemWithString:“OFF”]
, nil];

I port like that

CCArray* toggleMenuItems = CCArray::create(CCMenuItemFont::create(“ON”), CCMenuItemFont::create(“OFF”), NULL);

But I try to use toggleMenuItems like this but CCMenuItemToggle::createWithTarget doesn’t allow my code

CCMenuItemToggle *item3 = CCMenuItemToggle::createWithTarget(this, menu_selector(NewScene::doItemToggleCCLOG), toggleMenuItems);

Do you know how to use CCMenuItemFont’s CCArray or CCMenuItemFont’s other Array?


you should check the signatures of CCMenuItemToggle in CCMenuItemToggle.h file. CCMenuItemToggle with CCArray is not supported by Cocos2D-x. So in order to support CCArray with CCMenuItemToggle you need to modify the CCMenuItemToggle.h file and need to add your own custom create method and body for this.

Now question is how to write and add your own method? :slight_smile:

I think this should work. Give a try

1. First add the signature in CCMenuItemToggle.h file.

CCMenuItemToggle * createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems);

2. Add the method body in CCMenuItemToggle.cpp file.

CCMenuItemToggle * CCMenuItemToggle::createWithTarget(CCObject* target, SEL_MenuHandler selector, CCArray* menuItems)
CCMenuItemToggle pRet = new CCMenuItemToggle;
this~~>m_pSubItems = CCArray::create;
for ; z++)
menuItem = (CCMenuItem*)menuItems~~>objectAtIndex;

m_uSelectedIndex = UINT_MAX;
return pRet;


hello Paras Mendiratta

Thank you for replying
Not supporting CCArray is cocos2d-x’s policy?

I will try modify cocos2d-x’s code.

Why dont you do “pull request” to github the code?
Or if you it is troublesome I will try :>



Not sure, why CCArray is not used earlier. Maybe original team can answer it. I am not part of it. :slight_smile:

Here is the pull request:-


Good job!

I hope they take in original repository :slight_smile: