舒心、快乐,比什么都重要

cocos节点添加Touch监听代码

   
        this.node.on(cc.Node.EventType.TOUCH_START,
            function(t){
                console.log( "x" + t.getLocation().x + "y" + t.getLocation().y  )
                console.log(t.getLocation())
            },this)
        this.node.on(cc.Node.EventType.TOUCH_MOVE,
            function(t){
                console.log( "x" + t.getLocation().x + "y" + t.getLocation().y  )
                console.log(t.getLocation())
            },this)
             
        this.node.on(cc.Node.EventType.TOUCH_END,
            function(t){
                console.log( "x" + t.getLocation().x + "y" + t.getLocation().y  )
                console.log(t.getLocation())
            },this)
             
        this.node.on(cc.Node.EventType.TOUCH_CANCEL,
            function(t){
                console.log( "x" + t.getLocation().x + "y" + t.getLocation().y  )
                console.log(t.getLocation())
            },this)

代码需要放入onLoad函数内才可生效 

function(t) 函数内 t 参数为 Touch类型

Touch 类型

 

posted @ 2021-11-09 17:09  Arcturis  阅读(219)  评论(0编辑  收藏  举报