首页 > 其他 > 详细

给Layer添加触摸事件

时间:2016-01-08 21:51:22      阅读:182      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!