// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import EventName from "../EventName/EventName"; import LocalData from "../LocalData"; import MyComponent from "../Template/MyComponent"; const { ccclass, property } = cc._decorator; @ccclass export default class GameTips extends MyComponent { @property(cc.Label) Hight: cc.Label = null; @property(cc.Label) Left: cc.Label = null; @property(cc.Label) Right: cc.Label = null; // LIFE-CYCLE CALLBACKS: onLoad() { super.onLoad() } start() { this.regEvent(EventName.Update_CurrentHight, this.Update_CurrentHight, this) this.regEvent(EventName.YaoGanMove, this.YaoGanMove, this) } Update_CurrentHight(hightNum: number) { this.Hight.string = `${hightNum.toString()} M` if (LocalData.getInstance().getMaxRecord() < hightNum) { LocalData.getInstance().setMaxRecord(hightNum, '=') } } // YaoGanEnd(dir: cc.Vec3, power: number) { // // const result = parseFloat((power * 100).toFixed(2)); // // this.History.string = `历史:${this.GetAngle(dir)}° , ${result}%` // } YaoGanMove(dir: cc.Vec3, power: number) { const result = parseFloat((power * 100).toFixed(0)); this.Left.string = `${this.GetAngle(dir)}°` this.Right.string = `${this.FixLength(result)}%` } GetAngle(dir: cc.Vec3) { //根据朝向计算出夹角弧度 var angle = dir.signAngle(cc.v2(0, 1)); //将弧度转换为欧拉角 // (angle / Math.PI * 180).toFixed(0); return this.FixLength((angle / Math.PI * 180).toFixed(0).toString()) // let numStr = (angle / Math.PI * 180).toFixed(0).toString(); // let spacesToAdd = 3 - numStr.length; // let paddedStr = ""; // for (let i = 0; i < spacesToAdd; i++) { // paddedStr += " "; // } // return paddedStr + numStr; } FixLength(numStr) { let spacesToAdd = 4 - numStr.length; let paddedStr = ""; for (let i = 0; i < spacesToAdd; i++) { paddedStr += " "; } return paddedStr + numStr; } onDestroy(): void { super.onDestroy() } }