const {ccclass, property} = cc._decorator;
@ccclass
export default class CameraControlT extends cc.Component {
@property(cc.Node)
target: cc.Node = null;
// LIFE-CYCLE CALLBACKS:
visibleSize;
ratioX;
ratioY;
onLoad () {
cc.log("CameraControlT onLoad")
}
start () {
cc.log("CameraControlT start")
this.visibleSize = cc.view.getVisibleSize();
this.node.position = cc.p(this.visibleSize.width/2,this.visibleSize.height/2);
let po=this.target.parent.convertToWorldSpaceAR(this.target.position);
this.ratioX=this.visibleSize.width/2-po.x;
this.ratioY=this.visibleSize.height/2;
}
update (dt) {
let targetPos;
targetPos = this.target.parent.convertToWorldSpaceAR(this.target.position);
targetPos=cc.p(targetPos.x+this.ratioX,this.ratioY);
cc.log("CameraControlT update",targetPos)
this.node.position=targetPos;
}
}