bool HelloWorld::init()
{
if ( !Layer::init() )
{
return false;
}
Size size=Director::getInstance()->getVisibleSize();
auto label=LabelTTF::create("Click me","Courier",30);
label->setPosition(size.width/2,size.height/2);
addChild(label);
auto listener=EventListenerTouchOneByOne::create();
listener->onTouchBegan=[](Touch *t,Event *e){
if (e->getCurrentTarget()->getBoundingBox().containsPoint(t->getLocation())) {
log("OnTouchBegan");
}
return true;
};
listener->onTouchMoved=[](Touch* t,Event *e){
log("onTouchMoved");
};
listener->onTouchEnded=[](Touch* t,Event *e){
log("onTouchEnd");
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,label);
return true;
}