码迷,mamicode.com
首页 > 其他好文 > 详细

给Layer添加触摸事件

时间:2016-01-08 21:54:12      阅读:666      评论:0      收藏:0      [点我收藏+]

标签:

给Layer添加触摸事件可以在init方法中添加以下代码:

 

    auto touchlistener = EventListenerTouchOneByOne::create();
    touchlistener->setSwallowTouches(true);//设置是否想下传递触摸
    touchlistener->onTouchBegan = CC_CALLBACK_2(DirectionController::onTouchBegan, this);
    touchlistener->onTouchMoved = CC_CALLBACK_2(DirectionController::onTouchMoved, this);
    touchlistener->onTouchEnded = CC_CALLBACK_2(DirectionController::onTouchEnded, this);
    
    Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(touchlistener, 1.0);

  

然后就可以实现一下各个方法了

bool DirectionController::onTouchBegan(Touch* pTouch, Event* pEvent) {
    
    return true;
}

void DirectionController::onTouchMoved(Touch* pTouch, Event* pEvent) {
    Point touchPoint = pTouch->getLocationInView();
    Point touchGLPoint = Director::getInstance()->convertToGL(touchPoint);
}

void DirectionController::onTouchEnded(Touch* pTouch, Event* pEvent) {

}

  

给Layer添加触摸事件

标签:

原文地址:http://www.cnblogs.com/skyry/p/5114452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!