在bool HelloWorld::init()
1 //获取可见区域的大小 2 Size visibleSize = Director::getInstance()->getVisibleSize(); 3 //定义一个文本,显示内容 4 auto label = LabelTTF::create("Chick me", "Courier", 30); 5 //定义label的位置 6 label->setPosition(Point(visibleSize.width/2,visibleSize.height/2)); 7 addChild(label);//将label添加进去 8 //EventListenerTouchOneByOne表示一个接一个的触发,每次触摸只能监听到一个触摸点 9 auto listener = EventListenerTouchOneByOne::create(); 10 //onTouchBegan表示开始触摸的事件 11 listener->onTouchBegan = [](Touch *t, Event *e){ 12 13 log("onTouchBegan"); 14 15 return false; 16 }; 17 //getEventDispatcher获取事件的派发器, 18 //addEventListenerWithSceneGraphPriority(事件, 节点);添加事件监听器 19 Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, label);
时间: 2024-10-10 01:48:20