2022-09-20 15:50:01 +00:00
|
|
|
cc.Class({
|
2023-01-13 03:25:20 +00:00
|
|
|
extends: cc.Component,
|
2022-09-20 15:50:01 +00:00
|
|
|
|
2023-01-13 03:25:20 +00:00
|
|
|
properties: {
|
|
|
|
mapNode: {
|
|
|
|
type: cc.Node,
|
|
|
|
default: null
|
2022-09-20 15:50:01 +00:00
|
|
|
},
|
2023-01-13 03:25:20 +00:00
|
|
|
speed: {
|
|
|
|
type: cc.Float,
|
2023-02-04 10:33:49 +00:00
|
|
|
default: 100
|
2022-09-20 15:50:01 +00:00
|
|
|
},
|
2023-01-13 03:25:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onLoad() {
|
|
|
|
this.mainCamera = this.mapNode.parent.getChildByName("Main Camera").getComponent(cc.Camera);
|
|
|
|
this.mapScriptIns = this.mapNode.getComponent("Map");
|
|
|
|
},
|
2022-09-20 15:50:01 +00:00
|
|
|
|
2023-01-13 03:25:20 +00:00
|
|
|
start() {},
|
2022-09-20 15:50:01 +00:00
|
|
|
|
2023-01-13 03:25:20 +00:00
|
|
|
update(dt) {
|
|
|
|
const self = this;
|
|
|
|
if (!self.mainCamera) return;
|
|
|
|
if (!self.mapScriptIns) return;
|
|
|
|
if (!self.mapScriptIns.selfPlayerInfo) return;
|
|
|
|
if (!self.mapScriptIns.playerRichInfoDict) return;
|
2023-02-16 00:17:50 +00:00
|
|
|
const selfPlayerRichInfo = self.mapScriptIns.playerRichInfoDict.get(self.mapScriptIns.selfPlayerInfo.id);
|
2023-01-13 03:25:20 +00:00
|
|
|
if (!selfPlayerRichInfo) return;
|
|
|
|
const selfPlayerNode = selfPlayerRichInfo.node;
|
|
|
|
if (!selfPlayerNode) return;
|
2023-01-31 15:11:46 +00:00
|
|
|
const dst = cc.v2().sub(selfPlayerNode.position);
|
|
|
|
const pDiff = dst.sub(self.mapNode.position);
|
|
|
|
const stepLength = dt * self.speed;
|
|
|
|
if (stepLength > pDiff.mag()) {
|
|
|
|
self.mapNode.setPosition(dst);
|
|
|
|
} else {
|
|
|
|
pDiff.normalizeSelf();
|
|
|
|
const newMapPos = self.mapNode.position.add(pDiff.mul(dt * self.speed));
|
|
|
|
self.mapNode.setPosition(newMapPos);
|
|
|
|
}
|
2023-01-13 03:25:20 +00:00
|
|
|
}
|
2022-09-20 15:50:01 +00:00
|
|
|
});
|