// 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.show, this); } show (e:cc.Event.EventTouch) { //1.在日誌顯示觸控物件坐標 cc.log("x = " + e.getLocationX()); cc.log("y = " + e.getLocationY()); //2.在label顯示坐標 //抓lable-x ,y節點的lbel組件 var lblx = cc.find("Canvas/x").getComponent(cc.Label); var lbly = cc.find("Canvas/y").getComponent(cc.Label); //設定組件label的string參數 lblx.string = e.getLocationX().toString(); lbly.string = e.getLocationY().toString(); } // update (dt) {} }