• registerWithTouchDispatcher()函数的使用


    registerWithTouchDispatcher()函数的使用


    registerWithTouchDispatcher()函数主要用于注册Touch事件。


    当我们使用this->setTouchEnabled(true);方法开启触摸事件时,默认开启的是多点触摸,而我们有时只需要单点触摸就够了。实现方法如下:

    代码例子:
    void HelloWorld::registerWithTouchDispatcher()
    {
        CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
    }

    在registerWithTouchDispatcher()函数中注册的好处是:当CCLayer或CCLayer的派生类加载时就会调用会调用registerWithTouchDispatcher()函数 而当前CCLayer被移除时也会对注册的touch事件进行注销。


    argetedTouchDelegate.


    使用这种类型的delegate的好处:

    1.你不需要再处理NSSets了,CCTouchDispatcher 为了做了分离工作。每次调

    用的时候,你都会得到一个唯一的UITouch。

     

        这里我们将要覆盖 “ccTouchBegan” 和“ccTouchEnded” --第一个方法当第一个

    touch事件开始的时候被调用,另外一个是touch结束的时候被调用。


         值得注意的是,一定要重写ccTouchBegan函数让其返回true。不然就会出错,因

    为系统不会给你默认返回真。

     

    bool HelloWorld::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
        return true;
    }


    ccTouchEnded函数:


     

    void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
    {
        
    }






  • 相关阅读:
    安装pgsql
    ln软连接
    vsftp上传失败
    redis配置systemctl
    jmeter 录制排除模式
    数据库基本操作
    按日期排序
    angularjs的cache
    angularjs路由传递参数
    angularjs路由相关知识
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3162890.html
Copyright © 2020-2023  润新知