您的位置:首页 > 其它

1.处理屏幕触摸(单点触摸)

2016-05-24 16:41 351 查看

单点触摸

步骤:

1.需要设置一个tag值监听才能找到    

2.监听事件//1.创建监听对象
auto listener = EventListenerTouchOneByOne::create();
//2.定义监听对象的回调方法
listener->onTouchBegin = CC_CALLBACK_2(HelloWorld::onTouchBegin,this);
listener->onTouchMoved = CC_CALLBACK_2(HelloWorld::onTouchMoved,this);
listener->onTouchEnded = CC_CALLBACK_2(HelloWorld::onTouchEnded,this);
//3.事件分发器中注册
_eventDispatcher->addEventLsitenerWithSceneGraphPriority(listener,this);


3.监听事件的实现
bool HelloWorld::onTouchBegin(Touch* touch,Event *event){
auto lis = this->getChildByTag(111);
lis->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
return true;
}
void HelloWorld::onTouchMoved(Touch* touch,Event* event){
auto moveLis = this->getChildByTag(111);
moveLis->setPosition(Vec2(visibleSize.width/2,visibleSize.height/2));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: