1. 程式人生 > 其它 >cocos節點新增Touch監聽程式碼

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 型別