cocos2dx 点击事件分析(1)

前端之家收集整理的这篇文章主要介绍了cocos2dx 点击事件分析(1)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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;
};
原文链接:https://www.f2er.com/cocos2dx/343735.html

猜你在找的Cocos2d-x相关文章