Dear guys:
I feel very strange about my CCMenuItemSprite, I add many CCMenuItemSprite to my game,
most of them work fine, but now when I added a CCMenuItemSprite to a layer, and I’m sure this layer has been removed and cleaned from parent, and my menu is invisible,but it’s very strange! when I touch specific point on my screen, it triggers my menu event,
Does any body also has this problem?
My code is as the following:
menu added to background, and background added to a layer, on close button click,I remove and clean layer from parent.
CCSprite * fight = CCSprite::create(); fight->initWithSpriteFrameName("btn_small_fight.png"); CCSprite * fightClicked = CCSprite::create(); fightClicked->initWithSpriteFrameName("btn_small_fightclicked.png"); CCSprite * fightDisabled = CCSprite::create(); fightDisabled->initWithSpriteFrameName("btn_small_fightdisabled.png"); fightMenuItem = CCMenuItemSprite::create(fight,fightClicked,fightDisabled,this,menu_selector(WuXiaSpecialItem::onFightClick)); CCMenu* fightMenu = CCMenu::create(fightMenuItem,NULL); fightMenu->setPosition(CCPoint(450.0/scaleFactor,27.0/scaleFactor)); background->addChild(fightMenu);
and here is my code for firing onFightClick event.
`
setFlag(SPECIAL_FIGHT);
CCSize visibleSize = CCDirector::sharedDirector()->getWinSize();
float scaleFactor = CCDirector::sharedDirector()->getContentScaleFactor();
CCSprite* msgText = CCSprite::create();
msgText->initWithSpriteFrameName("msg_energycost.png");
msg = WuXiaMsgBox::create();
msg->setLeftButtonEvent("",this,0);
msgText->setPosition(CCPoint(0,70.0/480*visibleSize.height));
msg->addChild(msgText);
msgText->setScale(scaleFactor);
// 加入訊息
CCLabelTTF* costTTF = CCLabelTTF::create(energy.c_str(),"Marker Felt",30.0/800*visibleSize.width);
costTTF->setPosition(CCPoint(0.0/800*visibleSize.width,25.0/480*visibleSize.height));
msg->addChild(costTTF);
CCDirector::sharedDirector()->getRunningScene()->addChild(msg);
`