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.
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?
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;
pRet~~>CCMenuItem::initWithTarget;
this~~>m_pSubItems = CCArray::create;
this~~>m_pSubItems~~>retain;
for ; z++)
{
CCMenuItem menuItem = (CCMenuItem*)menuItems~~>objectAtIndex;
m_pSubItems~~>addObject(menuItem);
}
m_uSelectedIndex = UINT_MAX;
this->setSelectedIndex(0);
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 :>
Hello,
Not sure, why CCArray is not used earlier. Maybe original team can answer it. I am not part of it.
Here is the pull request:-
cocos2d:master
← CodeSnooker:master
opened 07:14AM - 12 Mar 13 UTC
Good job!
I hope they take in original repository