2022-09-20 15:50:01 +00:00
|
|
|
cc.Class({
|
|
|
|
extends: cc.Component,
|
|
|
|
|
|
|
|
properties: {
|
|
|
|
mapNode: {
|
|
|
|
type: cc.Node,
|
|
|
|
default: null
|
|
|
|
},
|
2022-10-10 06:33:04 +00:00
|
|
|
speed: {
|
|
|
|
type: cc.Float,
|
|
|
|
default: 500
|
|
|
|
},
|
2022-09-20 15:50:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad () {
|
|
|
|
this.mainCamera = this.mapNode.parent.getChildByName("Main Camera").getComponent(cc.Camera);
|
|
|
|
this.mapScriptIns = this.mapNode.getComponent("Map");
|
|
|
|
},
|
|
|
|
|
|
|
|
start() {},
|
|
|
|
|
|
|
|
update(dt) {
|
|
|
|
const self = this;
|
|
|
|
if (!self.mainCamera) return;
|
|
|
|
if (!self.mapScriptIns) return;
|
|
|
|
if (!self.mapScriptIns.selfPlayerInfo) return;
|
|
|
|
if (!self.mapScriptIns.playerRichInfoDict) return;
|
2022-09-26 03:16:18 +00:00
|
|
|
const selfPlayerRichInfo = self.mapScriptIns.playerRichInfoDict.get(self.mapScriptIns.selfPlayerInfo.id);
|
2022-09-20 15:50:01 +00:00
|
|
|
if (!selfPlayerRichInfo) return;
|
|
|
|
const selfPlayerNode = selfPlayerRichInfo.node;
|
|
|
|
if (!selfPlayerNode) return;
|
2022-10-10 06:33:04 +00:00
|
|
|
const pDiff = selfPlayerNode.position.sub(self.mainCamera.node.position);
|
|
|
|
pDiff.normalizeSelf();
|
|
|
|
const newCamPos = self.mainCamera.node.position.add(pDiff.mul(dt*self.speed));
|
|
|
|
self.mainCamera.node.setPosition(newCamPos);
|
2022-09-20 15:50:01 +00:00
|
|
|
}
|
|
|
|
});
|