Hi guys, im trying to do a battleship game and I need to press a button to start the game and I need to remove this button after pressed.
I thought of some ideas to deal with this problem
- Pass a layer parameter thry my cc_callback function so that I could remove the child from the layer. (but i dont know how to do this)
- Somehow get my current layer inside the function called when I click the button and remove the child from there.
Here is my code:
bool GameScene::init()
{
if ( !Layer::init() )
{
return false;
}
auto size = Director::getInstance()->getWinSize();
auto menu_item_1 = MenuItemImage::create("fight.png", "fight.png",
CC_CALLBACK_1(GameScene::ImageButton, this));
menu_item_1->setPosition(Point(visibleSize.width/5*4, visibleSize.height/5));
menu_item_1->setTag(99);
auto *menu = Menu::create(menu_item_1, NULL);
menu->setPosition(Point(0,0));
addChild(menu);
return true;
}
void GameScene::ImageButton(cocos2d::Ref *pSender){
CCLOG(“ImageButton”);
this->removeChildByTag(99);
I would like to have access to the layer here!!
}
Thanks!!