// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { onLoad () { this.node.on("touchstart", this.show1, this); } show1 (e:cc.Event.EventTouch) { //注意:touch觸控事件的坐標是世界坐標,不是本地Local坐標 //把『世界坐標』轉成『本地坐標』的方法 //(1) 本地坐標.x = 貓世界坐標.x - Canvas.width/2 //(2) 本地坐標.y = 貓世界坐標.y - Canvas.height/2 //抓取貓節點 var node1 = cc.find("Canvas/貓"); //抓取Canvas節點 let $canvas1 : cc.Node = cc.find("Canvas"); //貓移動到觸控點位置 node1.setPosition(cc.v2(e.getLocationX()-$canvas1.width / 2, e.getLocationY()-$canvas1.height / 2)); } // update (dt) {} }