Hello!
I have a problem with a start button in my game. I’m using cocos studio 2, created a scene there, put the button and everything looks fine however the button is not responding to any touches.
My code looks like this:
bool MainScene::init()
{
if ( !Layer::init() )
{
return false;
}
auto rootNode = CSLoader::createNode( "MainScene.csb" );
rootNode->setName("root");
rootNode->setContentSize(size);
addChild(rootNode);
setStartButton();
return true;
}
setting up the button:
void MainScene::setStartButton()
{
startButton = (Button*)this->getChildByName("root")->getChildByName( "startButton" );
startButton->addTouchEventListener( CC_CALLBACK_2( MainScene::touchEventStartButton, this ) );
}
and the touch event method:
void MainScene::touchEventStartButton(Ref *pSender, Widget::TouchEventType type)
{
switch (type)
{
case Widget::TouchEventType::BEGAN:
// TODO
break;
case Widget::TouchEventType::ENDED:
// TODO
break;
default:
// TODO
break;
}
}
What am I missing guys? Do I need to initialize something in the init method? Or set something in cocos studio? Help!