DelayNoMore/frontend/assets/scripts/CameraTracker.js

35 lines
894 B
JavaScript
Raw Normal View History

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,
default: 500
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;
const selfPlayerRichInfo = self.mapScriptIns.playerRichInfoDict.get(self.mapScriptIns.selfPlayerInfo.Id);
if (!selfPlayerRichInfo) return;
const selfPlayerNode = selfPlayerRichInfo.node;
if (!selfPlayerNode) return;
self.mapNode.setPosition(cc.v2().sub(selfPlayerNode.position));
}
2022-09-20 15:50:01 +00:00
});