cameraCtrl
cameraCtrl
import Tool from "../farework/scripts/Tool";
const { ccclass, property } = cc._decorator;
@ccclass
export default class cameraCtrl extends cc.Component {
@property(cc.Camera)
camera3D: cc.Camera = null;
onLoad(): void {
// this.camera3D = Tool.Instance.findNode("Camera", this.node)
}
followOne(node, pos = cc.v2(0, 0), zoomRatio = 1.45, time = 0.5) {
this.follow(this.camera3D, node, pos, zoomRatio, time)
}
follow(camera, node, pos = cc.v2(0, 0), zoomRatio = 1.45, time = 0.5) {
if (!cc.isValid(node)) return;
camera.node.parent = node
camera.node.setPosition(pos)
cc.tween(camera)
.to(time, { zoomRatio: zoomRatio })
.start()
}
moveBack() {
this.camera3D.node.setPosition(0, 0)
this.camera3D.zoomRatio = 1
this.camera3D.node.parent = this.node
}
}