cocos2dx 点击事件分析(1)

来源:互联网 发布:高德软件股票行情 编辑:程序博客网 时间:2024/04/30 10:32
CCTouch类是每个点击事件处理过程中,都需要使用的类,因为android的屏幕坐标和OpenGL的坐标的不同,而且在屏幕适配时,有缩放,所以需要把屏幕坐标转化为OpenGL的坐标坐标。class CC_DLL CCTouch : public CCObject{public:    /**     * @js ctor     */    CCTouch()        : m_nId(0),        m_startPointCaptured(false)    {}    /** returns the current touch location in OpenGL coordinates */    CCPoint getLocation() const;    /** returns the previous touch location in OpenGL coordinates */    CCPoint getPreviousLocation() const;    /** returns the start touch location in OpenGL coordinates */    CCPoint getStartLocation() const;    /** returns the delta of 2 current touches locations in screen coordinates */    CCPoint getDelta() const;    /** returns the current touch location in screen coordinates */    CCPoint getLocationInView() const;    /** returns the previous touch location in screen coordinates */    CCPoint getPreviousLocationInView() const;    /** returns the start touch location in screen coordinates */    CCPoint getStartLocationInView() const;        void setTouchInfo(int id, float x, float y)    {        m_nId = id;        m_prevPoint = m_point;        m_point.x   = x;        m_point.y   = y;        if (!m_startPointCaptured)        {            m_startPoint = m_point;            m_startPointCaptured = true;        }    }    /**     *  @js getId     */    int getID() const    {        return m_nId;    }private:    int m_nId;    bool m_startPointCaptured;    CCPoint m_startPoint;    CCPoint m_point;    CCPoint m_prevPoint;};

0 0
原创粉丝点击