当前场景中有三个消息框,这里我分别命名为_grannyMessage、_grannyMessage2、_grannyMessage3。当在场景中创建 _grannyMessage3 时,我想让 _grannyMessage 从场景中消失。我正在尝试使用“this->removeChild(_grannyMessage);” 函数,但它似乎不起作用,我是否调用了错误的函数?非常感谢
auto grannyListener = EventListenerTouchOneByOne::create();
grannyListener -> setSwallowTouches(true);
grannyListener -> onTouchBegan =[this](Touch *touch, Event *event){
MessageBoxes *_grannyMessage =
MessageBoxes::create("The hen can lay an egg everyday");
if(i==0){
_grannyMessage->setPosition(Vec2(600, 450));
addChild(_grannyMessage);
}
else if (i==1)
{
MessageBoxes *_grannyMessage2 =
MessageBoxes::create("2 yuan, that's all I can offer you for the hen");
_grannyMessage2->setPosition(Vec2(400, 450));
addChild(_grannyMessage2);
}
else if (i==2)
{
this->removeChild(_grannyMessage);
MessageBoxes *_grannyMessage3 =
MessageBoxes::create("Well");
_grannyMessage3->setPosition(Vec2(800, 450));
addChild(_grannyMessage3);
}
else
{
return false;
}
i++;
return false;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(grannyListener, this);